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

Hello,

 

I am trying to execute the below code but the execution stops unexpectedly. For reference, the min_date is 15Feb1993 and the max_date is 15Dec2013. At the bottom of the macro I have also pasted macro variable resolution from the log. Any help is greatly appreciated. Thanks

 

%macro run_all;

proc sql noprint;

select max(datepart(current_date)) format=date9., min(datepart(current_date)) format=date9.

into :max_date, :min_date

from edf;

quit;

%do %until ("&min_date."d ge "&max_date."d);

%let var_2= %sysfunc(inputn(&min_date,date9.),monyy5.);

%cohort(&min_date,&var_2);

%let min_date=%sysfunc(intnx(month,"&min_date."d,3,same),date9.);

%put &min_date.;

%end;

%mend run_all;

 

SYMBOLGEN: Macro variable MIN_DATE resolves to 15FEB1993

MLOGIC(RUN_ALL): %PUT &min_date.

SYMBOLGEN: Macro variable MIN_DATE resolves to 15MAY1993

15MAY1993

SYMBOLGEN: Macro variable MIN_DATE resolves to 15MAY1993

SYMBOLGEN: Macro variable MAX_DATE resolves to 15DEC2013

MLOGIC(RUN_ALL): %DO %UNTIL() condition is TRUE; loop will not iterate again.

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @sai_ch,

 

To fix the issue pointed out by Astounding, simply apply %SYSEVALF to the %UNTIL condition:

%do %until(%sysevalf("&min_date."d ge "&max_date."d));

The %SYSEVALF function helps the macro processor to understand SAS dates (and more).

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Macro language does not understand SAS dates.  It thinks that %DO %UNTIl is comparing two character strings.  So the first time through the loop, the %UNTIL condition is true and the loop ends. because "15M is greater than "15D. 

 

Lucky for you that it stopped.  With a few changes to the dates, you might have constructed an infinite loop.

FreelanceReinh
Jade | Level 19

Hello @sai_ch,

 

To fix the issue pointed out by Astounding, simply apply %SYSEVALF to the %UNTIL condition:

%do %until(%sysevalf("&min_date."d ge "&max_date."d));

The %SYSEVALF function helps the macro processor to understand SAS dates (and more).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1069 views
  • 4 likes
  • 3 in conversation