Hi there,
The following codes has generated an error message "Nesting of %IF statements in open code is not supported. %IF ignored. Skipping to next %END statement." But if I deleted the red part of the codes (i.e., the 3 lines of codes starting from %else %if ... %then %do) , then the codes worked fine and generated the correct answer.
I also changed part of the problematic codes to (¤t_month_num=9 or ¤t_month_num=10), and then changed it to (¤t_month_num=10). None of them work.
Can you please point out my mistake, and suggest a workaround solution? Any help or any comments is highly appreciated. Thanks for your help!
%let current_month_num = %sysfunc(month(%sysfunc(today())));
%if (¤t_month_num=1 or ¤t_month_num=2 ) %then %do;
%put no report will be generated;
%end;
%else %if (¤t_month_num=9 or ¤t_month_num=8 or ¤t_month_num=7) %then %do;
%put quarter to date comparison report;
%end;
%else %do;
%put not in Q3 and not in Jan or Feb;
%end;
Nesting of %IF statements in open code is not supported
Nested %IF is not supported in open code. The code in red is a nested %IF, in other words an %IF within another %IF. You cannot code this way outside of a macro.
Your code seems like it should run inside a macro.
Remove the nesting. Just use three independent %IF blocks.
%let current_month_num = %sysfunc(month(%sysfunc(today())));
%if (¤t_month_num=1 or ¤t_month_num=2 ) %then %do;
%put no report will be generated;
%end;
%if (¤t_month_num=9 or ¤t_month_num=8 or ¤t_month_num=7) %then %do;
%put quarter to date comparison report;
%end;
%if (¤t_month_num=3
or ¤t_month_num=4
or ¤t_month_num=5
or ¤t_month_num=6
or ¤t_month_num=10
or ¤t_month_num=11
or ¤t_month_num=12
) %do;
%put not in Q3 and not in Jan or Feb;
%end;
Hi @ssll,
You could avoid the %IF-%THEN/%ELSE statements like this:
%let m=NNEEEERRREEE;
%let N=no report will be generated;
%let R=quarter to date comparison report;
%let E=not in Q3 and not in Jan or Feb;
%let c=%substr(&m,¤t_month_num,1);
%put &&&c;
However, I suspect that you actually want to execute some reporting statements if &c=R. In this case you could at least avoid the nesting:
%let m=NNEEEERRREEE;
%let N=no report will be generated;
%let E=not in Q3 and not in Jan or Feb;
%let c=%substr(&m,¤t_month_num,1);
%if &c=R %then %do;
%inc 'C:\Temp\myQtoDreport.sas' / source;
%end;
%else %do;
%put &&&c;
%end;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.