BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vicky07
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

A quick look at your code tells me you are missing %by instead of by

novinosrin
Tourmaline | Level 20

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

 

vicky07
Quartz | Level 8

I knew i was doing something silly. Thank you!

ballardw
Super User

I hope you are testing that day(today()) is greater than 20 before executing else you will have an infinite loop.

vicky07
Quartz | Level 8
It will be actually1. I put 20 for illustration purpose. Thanks.

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3546 views
  • 0 likes
  • 3 in conversation