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;
Hi PaigeMiller, you are right, I have tested putting those codes inside a macro, and it worked and generated the correct output. Sorry for my late reply and thank you so much for your help!
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.
Hi PaigeMiller, you are right, I have tested putting those codes inside a macro, and it worked and generated the correct output. Sorry for my late reply and thank you so much for your help!
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 Tom, sorry for my late reply and thank you so much for your reply. Yes I agree with you, using 3 independent %if blocks is a workaround solution cuz I just tested using 3 independent if blocks. Thanks for your help!
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.