I got error when I was trying to use macro nested loop in SAS:
%Let t1=30;
%Let t2=40;
%Let t3=50;
%Let t4=60;
%Let t5=70;
%macro Age(time);
%Do I = 1 %to &time.;
data Milk&I;
set Milk;
/*If Age is less than 30, MilkF and MilkA after 30 should be 0, same for 40-70*/
where (age<&&t&I. and (%Do I = &I. %to 5;
MilkF&&t&I. ne 0 or MilkA&&t&I. ne 0 ;
%end;) ) ;
run;
%end;
%mend Age;
%Age(5)
The error shows behind the last "ne 0;" Syntax Error. What's the problem? Thanks for your help!
UPDATE: The output from macro I want is (takeing t1=30 as an example):
where (age<30 and (
MilkF30 ne 0 or MilkA30 ne 0 or
MilkF40 ne 0 or MilkA40 ne 0 or
MilkF50 ne 0 or MilkA50 ne 0 or
MilkF60 ne 0 or MilkA60 ne 0 or
MilkF70 ne 0 or MilkA70 ne 0
) ) ;
So I have changed my code to
where (age<&&t&I. and
(%Do I = &I. %to 5;
MilkFreq&&t&I. ne 0 or MilkAmnt&&t&I. ne 0 or
%end;
) ) ;
Error:
) ) ; run;
-
22
76
"ERROR: Syntax error while parsing WHERE clause." So what happened now?
mikf30 ne 0 or milka30 ne 0;
There's no if or variable assigned..and if you're trying to list the conditions then you may have too many semicolons. - Reezawhere
condition. The do loop in the bracket as well as age<&&t&I. are the where condition. - Yukun