Question

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. I tried proc sql with disappointing results.

Any help? Thanks!

Was it helpful?

Solution

You cannot use macro loops outside of a macro. Enclose the last lines in a macro like you do the question macro.

Also, you need to end the loop:

%macro myloop();
   %do i=1 %to 5;

      <stuff>

   %end
%mend;

%myloop;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top