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

Hi All,

 

I have a macro variable like below which is triggered in my first program.

 

%let ddmmyyyy = "28Feb2019"d;	

On another program inside a macro i have a simple IF statement, see below:

 

%if &ddmmyyyy. >= '31DEC2018'd %then %do;

 

I expect this to return a TRUE value however when i run the macro, the IF statement returns FALSE. See below for the extract from the LOG. 

MLOGIC(My_Macro): Beginning execution.
SYMBOLGEN: Macro variable DDMMYYYY resolves to "28Feb2019"d
MLOGIC(My_Macro): %IF condition &ddmmyyyy. >= '31DEC2018'd is FALSE
MLOGIC(My_Macro): Ending execution.

 

It seems to return false if the days are less than 31 as it runs as expected for 31/12 and 31/01. Does anyone know why this is happening? I have a solution in place but would like to understand why this is happening.

 

Thanks

 

Using SAS EG, version 9.2

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Macro language does not resolve dates into numeric values on SAS's date scale.  It makes comparisons based on the characters it finds, just as if you asked:

 

%if abc > xyz %then ....;

 

If you want to tell macro language to convert the date values to numeric dates, apply %sysevalf:

 

%if %sysevalf(&ddmmyyyy >= '31DEC2018'd) %then %do;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Macro language does not resolve dates into numeric values on SAS's date scale.  It makes comparisons based on the characters it finds, just as if you asked:

 

%if abc > xyz %then ....;

 

If you want to tell macro language to convert the date values to numeric dates, apply %sysevalf:

 

%if %sysevalf(&ddmmyyyy >= '31DEC2018'd) %then %do;

PaigeMiller
Diamond | Level 26

You can't do this with macro variables. Macro variables are simply considered text, they have no other meaning — and are not interpreted as actual dates. So the test you are doing in the %IF is testing to see if the text string is greater than the other text string, and it is not greater, thus you get FALSE.

 

You could use something like this:

%if %sysevalf(&ddmmyyyy. >= '31DEC2018'd) %then ...

 

 

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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