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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.