BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ssll
Calcite | Level 5

Hi there,

I have entered the following 2 sets of codes, even though sas log says there is no syntax error but sas has generated the wrong output for both set of codes(both sets of codes shown below were pasted from sas log ).  Can you please point out my mistake?  Or is there a glitch in sas? Any help or any comment is highly appreciated. Thanks a lot for your help!  

 

first set of codes:

71 %let today = %sysfunc(today(), date9.);
72 %put &today;
21SEP2025
73 %let Ichoose = %sysfunc(putn('01Nov2025'd, date9.));
74 %put &Ichoose;
01NOV2025
75 %if %sysevalf(&today < &Ichoose) %then %do ;
76 %put abcd;
77 %end;
78 %else %do;
79 %put efgh ;
efgh
80 %end;
 
second set of codes:
69 %let today = %sysfunc(today(), date9.);
70 %put &today;
21SEP2025
71 %let Ichoose = %sysfunc(putn('01Nov2025'd, date9.));
72 %put &Ichoose;
01NOV2025
73 %if %sysevalf(&today > &Ichoose) %then %do ;
74 %put abcd;
abcd
75 %end;
76 %else %do;
77 %put efgh ;
78 %end;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks right to me.

The string 01NOV2025 is definitely less than the string 21SEP2025 since the digit 0 is less than the digit 2.

 

If you wanted to compare two dates you could either remove the formatting when generating the macro variables.

%let today = %sysfunc(today());
%let Ichoose = %sysevalf('01Nov2025'd);

Then your comparison would be comparing two digit strings so %SYSEVALF() would treat them as numbers.

 

Or leave the macro variables the same and instead convert the values to date literals when doing the comparison.

%if %sysevalf("&today"d < "&Ichoose"d) %then %do ;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Looks right to me.

The string 01NOV2025 is definitely less than the string 21SEP2025 since the digit 0 is less than the digit 2.

 

If you wanted to compare two dates you could either remove the formatting when generating the macro variables.

%let today = %sysfunc(today());
%let Ichoose = %sysevalf('01Nov2025'd);

Then your comparison would be comparing two digit strings so %SYSEVALF() would treat them as numbers.

 

Or leave the macro variables the same and instead convert the values to date literals when doing the comparison.

%if %sysevalf("&today"d < "&Ichoose"d) %then %do ;

 

ssll
Calcite | Level 5
Hi Tom, I just tried both of your suggestions in sas, and I got the correct answer . You solved my problem, thanks so very much!

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

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 236 views
  • 5 likes
  • 2 in conversation