Hello,
I couldn't figure out what i am doing wrong in the below code but basically I am trying to get day from today's date and use that as "start" value for the do loop iteration. Could someone tell me why this isn't working? Thank You!
%macro test;
%do n = %sysfunc(day(%sysfunc(today())-1)) %to 20 by -1;
/*%do n = 24 %to 20;*/
%Let n1 = %eval(&n.- 1);
%put N1 => &n1.;
%end;
%mend;
%test;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 23 by -1
ERROR: The %TO value of the %DO N loop is invalid.
ERROR: The macro AA will stop executing.
I ran a test after the change i made, here is the log:
1185 %macro test;
1186 %do n = %sysfunc(day(%sysfunc(today())-1)) %to 20 %by -1;
1187 /*%do n = 24 %to 20;*/
1188 %Let n1 = %eval(&n.- 1);
1189 %put N1 => &n1.;
1190 %end;
1191
1192 %mend;
1193 %test;
N1 => 23
N1 => 22
N1 => 21
N1 => 20
N1 => 19
A quick look at your code tells me you are missing %by instead of by
I ran a test after the change i made, here is the log:
1185 %macro test;
1186 %do n = %sysfunc(day(%sysfunc(today())-1)) %to 20 %by -1;
1187 /*%do n = 24 %to 20;*/
1188 %Let n1 = %eval(&n.- 1);
1189 %put N1 => &n1.;
1190 %end;
1191
1192 %mend;
1193 %test;
N1 => 23
N1 => 22
N1 => 21
N1 => 20
N1 => 19
I knew i was doing something silly. Thank you!
I hope you are testing that day(today()) is greater than 20 before executing else you will have an infinite loop.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.