0

您好我正在尝试在 SAS 中使用 BY GROUP 语句来生成多个图表。我想将每个图打印到以 BY GROUP 变量值命名的单个文件中,另外我想为每个图添加一个脚注,我想在图 1 中添加文本“此图为 2300-01”并希望将其增加1 用于“此图为 2300-02”的下一张图,依此类推。

goptions reset=all border;
data grainldr;
length country $ 3 type $ 5;
input year country $ type $ amount;
megtons=amount/1000;
datalines;
1995 BRZ  Wheat    1516
1995 BRZ  Rice     11236
1995 BRZ  Corn     36276
1995 CHN  Wheat    102207
1995 CHN  Rice     185226
1995 CHN  Corn     112331
1995 INS  Wheat    .
1995 INS  Rice     49860
1995 INS  Corn     8223
1995 USA  Wheat    59494
1995 USA  Rice     7888
1995 USA  Corn     187300
; 

 proc sort data=grainldr out=temp;
 by country;
 run;

 proc sgplot data=temp (where=(megtons gt 31));
 by country;

 series x=type y= amount;
 series x=type y=megtons;
 title "Leading #byval(country) Producers"
    j=c "1995 and 1996";
 footnote1 j=r  "This graph is 2300-&XY."; 
 run;

辞职;

4

1 回答 1

1

如果你的数据集中有一个 BY 变量,你可以使用它。例如,如果您有一个名为 CID(国家/地区 ID)的变量,并且它的值是“01”、“02”等,那么您可以执行以下操作:

proc sort data=grainldr out=temp;
  by country cid;
run;

footnote1 j=r  "This graph is 2300-#byval2"; 
proc sgplot data=temp (where=(megtons gt 31));
  by country cid;
  ...
  ...

跑;

在这种情况下,#BYVAL2 指的是第二个 BY 变量的值,即 CID

于 2012-02-27T15:48:16.043 回答