[英]Trouble with SAS do loop
This is my code: 这是我的代码:
libname Project 'XXX'; run;
%let dname = q1males;
%let Gender = 'Male';
%let samp = q1msamp;
%let stats = Malestats;
data project.data1; set project.data;
id = _n_;
run;
data project.&dname; set project.data1;
if Gender = &Gender;
run;
%macro question;
%do i = 1 %to 5;
proc surveyselect data = project.&dname method = SRS sampsize = 27
out = project.&samp;
id _all_;
run;
proc print data = project.&samp;
run;
proc sql;
create table project.&stats&i as
select 'Weight',
avg(Weight) as Mean format 10.2 label 'Mean Weight',
std(Weight) as Std format 10.2 label 'Std. Dev Weight'
from project.&samp;
QUIT;
%end;
%mend question;
%question;
%do j = 1 %to 5;
data project.merged&j;
merge project.femalestats&j project.malestats&j;
by _Tema003 Mean Std;
run;
Everything works fine except for the last 6 lines, starting with %do j = 1 %to 5. I run the code preceding it twice for Female and Male datasets, and with the last 6 lines I am trying to merge the female and male datasets (ex: project.Femalestats1 merged with project.Malestats1 to be in a new dataset, project.merged1.) My log isn't showing errors, but I'm not getting the merged datasets either. 除了最后6行外,一切都正常,从%do j = 1%到5开始。我对雌性和雄性数据集运行了两次代码,而后6行我试图合并雌性和雄性数据集(例如:project.Femalestats1与project.Malestats1合并到新的数据集project.merged1中。)我的日志没有显示错误,但是我也没有得到合并的数据集。 I tried proc sql with disappointing results.
我尝试了proc sql,结果令人失望。
Any help? 有什么帮助吗? Thanks!
谢谢!
You cannot use macro loops outside of a macro. 您不能在宏外部使用宏循环。 Enclose the last lines in a macro like you do the
question
macro. 像处理
question
宏一样,将最后一行括在宏中。
Also, you need to end the loop: 另外,您需要结束循环:
%macro myloop();
%do i=1 %to 5;
<stuff>
%end
%mend;
%myloop;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.