This is within a macro function.
Example termdate = 01/01/2007
%do II = 0 %to 11; %let x = %sysfunc(intnx(month,&termdate.,&ii,B),Date9.); %let t = %str(%')&x.%str(%')d; %put &t.; %put ⅈ %if %sysevalf(&t.) ge '01FEB2018'd %then %do;
the %put &t. produces:
'01JAN2007'd
but then when I use it in the %if statement below
it evaluates to TRUE when using Mlogic option.
It should be False.
This is how it should look when the macro variable has been resolved.
%if '01JAN2007'd ge '01FEB2018'd %then %do;
Should be false but it comes out true.
try :
%if %sysevalf(&t. ge '01FEB2018'd) %then %do;
Macro language doesn't understand dates. It understands character strings. If you want to force it to make the "right" comparison, you can do it with:
%if %sysevalf(&t.) ge %sysevalf('01FEB2018'd) %then %do;
Is that all your code? If so, you should use a data step and data step loop, not a macro loop.
@mhodge20 wrote:
This is within a macro function.
Example termdate = 01/01/2007
%do II = 0 %to 11; %let x = %sysfunc(intnx(month,&termdate.,&ii,B),Date9.); %let t = %str(%')&x.%str(%')d; %put &t.; %put ⅈ %if %sysevalf(&t.) ge '01FEB2018'd %then %do;the %put &t. produces:
'01JAN2007'd
but then when I use it in the %if statement below
it evaluates to TRUE when using Mlogic option.
It should be False.
This is how it should look when the macro variable has been resolved.
%if '01JAN2007'd ge '01FEB2018'd %then %do;Should be false but it comes out true.
@mhodge20 wrote:
This is within a macro function.
Example termdate = 01/01/2007
the %put &t. produces:
'01JAN2007'd
but then when I use it in the %if statement below
it evaluates to TRUE when using Mlogic option.
It should be False.
This is how it should look when the macro variable has been resolved.
%if '01JAN2007'd ge '01FEB2018'd %then %do;Should be false but it comes out true.
No it shouldn't. Strings are compared one character at a time until a difference (if any) is found: 0=0, 1=1 but J>F.
for added fun check on this
%if '01JAN2007'd ge '01feb2018'd %then %do;
The condition in a %IF is normally evaluated using the %EVAL() macro function. That function does not handle floating point numbers or literals. So you need to generate your own test using the %SYSEVALF() macro function instead if you are comparing date literals.
Also you need to convert your date like string into a date value, either an actual number of days or a date literal, before you can compare dates.
%let datenumber = %sysfunc(intnx(month,&termdate.,&ii,B));
%let dateliteral = "%sysfunc(intnx(month,&termdate.,&ii,B),Date9.)"d;
%if %sysevalf(&datenumber. ge '01FEB2018'd) %then %do;
%if %sysevalf(&dateliteral. ge '01FEB2018'd) %then %do;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.