我有一个如下所示的数据集:
data have;
input name $ class $ time score;
cards;
chewbacca wookie 1 97
chewbacca wookie 2 100
chewbacca wookie 3 95
saruman wizard 1 79
saruman wizard 2 85
saruman wizard 3 40
gandalf wizard 1 22
gandalf wizard 2 50
gandalf wizard 3 87
bieber canadian 1 50
bieber canadian 2 45
bieber canadian 3 10
;
run;
Run Code Online (Sandbox Code Playgroud)
我正在创建一个程序来完成两件事:1.打印每个不同类的数据2.为每个名称创建一个散点图x =时间y =得分.
执行下面的代码将说明我想要的输出:
data chewbacca saruman gandalf bieber;
set have;
if name='chewbacca' then output chewbacca;
else if name='saruman' then output saruman;
else if name='gandalf' then output gandalf;
else if name='bieber' then output bieber;
run;
title 'Report for wookie';
proc print data=have;
where class='wookie';
run;
title 'Plot Chewbacca';
proc sgplot data=chewbacca;
scatter x=time y=score;
run;
title 'Report for wizard';
proc print data=have;
where class='wizard';
run;
title 'Plot Saruman';
proc sgplot data=saruman;
scatter x=time y=score;
run;
title 'Plot Gandalf';
proc sgplot data=gandalf;
scatter x=time y=score;
run;
title 'Report for canadian';
proc print data=have;
where class='canadian';
run;
title 'Plot Bieber';
proc sgplot data=bieber;
scatter x=time y=score;
run;
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想自动化这个.我一直试图设置它,但我错过了一些东西.这是我的尝试:
proc sql;
select count(distinct name) into :numname
from have;
%let numname=&numname;
select distinct name into :name1 - :name&numname
from have;
select count(distinct class) into :numclass
from have;
%let numclass=&numclass;
select distinct class into :class1 - :class&numclass
from have;
quit;
%macro printit;
%do i = 1 %to &numclass;
title 'Report for &&class&i';
proc print data=have;
where class=&&class&i;
run;
/*insert sgplot here*/
%end;
%mend;
%printit;
Run Code Online (Sandbox Code Playgroud)
请帮忙.无法获得语法排序....
谢谢.
我看到4个问题.
宏只会在双引号内解析.单引号掩盖了分辨率.所以将title语句更改为:
title "Report for &&class&i";
类变量是一个字符串.您需要在where子句中引用字符串:
where class="&&class&i";
您不需要生成单独的数据集.您可以在为其指定数据时添加where子句SGPLOT
proc sgplot data=have(where=(name="&&name&i"));
名称和类的数量不同,因此您需要两个循环.
编辑:还看看SGPANEL
和/或SGRENDER
.您可以在1次调用中生成所有图表.
归档时间: |
|
查看次数: |
473 次 |
最近记录: |