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
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;
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;
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 ...
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!
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.