Hi,
I was trying to create dataset names like shown below and get an error message
"OPEN CODE RECURSION DETECTED"
Could you help me resolve this issue??
Thanks
%let month3=JAN
%let month2=FEB
data &month3 &month2;
if conditions...then output "&month3";
if conditions...then output "&month2";
run;
Generally, that error means you have something wrong in your code, for example missing a semi colon or mismatched quotation marks.
Also, think of how that resolves:
%let month3=JAN
%let month2=FEB
data &month3 &month2;
if conditions...then output "&month3";
if conditions...then output "&month2";
run;
BECOMES
data JAN FEB;
if conditions...then output "JAN";
if conditions...then output "FEB";
run;
Hopefully you can easily see from that your macro variables should not be in quotation marks.
The best practice for what you're trying to do: DON"T DO IT.
If you ABSOLUTELY, really decide you want to go that way then see the best ways:
Generally, that error means you have something wrong in your code, for example missing a semi colon or mismatched quotation marks.
Also, think of how that resolves:
%let month3=JAN
%let month2=FEB
data &month3 &month2;
if conditions...then output "&month3";
if conditions...then output "&month2";
run;
BECOMES
data JAN FEB;
if conditions...then output "JAN";
if conditions...then output "FEB";
run;
Hopefully you can easily see from that your macro variables should not be in quotation marks.
The best practice for what you're trying to do: DON"T DO IT.
If you ABSOLUTELY, really decide you want to go that way then see the best ways:
Hi,
Thanks for the quick response.
I was thinking that for a macro variable to be resolved I have to use DOUBLE QUOTES always
So from your explanation it seems that when using macro variables for the data then it has to be in QUOTES
For example to pick all the records in JAN from TIME variable below then we need to use " quotes like "&start3"
Am i right??????
Thanks
%let month3=JAN
%let month2=FEB
data &month3 &month2;
"&start3"D <=datepart(TIME)<="&end3"D.then output &month3;
if conditions...then output &month2;
run;
No you're not right.
See the documentation for examples of usage.
Thanks for the help.
If you want a macro variable to resolve INSIDE OF QUOTES then the outer quotes need to be dquote marks (") not single quote marks ('). If there are no quotes involved then resolution of a macro variable reference (or other macro statements) is not an issue.
Hi Tom.
Is it not that the INNER QUOTE HAS TO BE A DOUBLE QUOTE AND NOT THE OUTER!!!!!
example:
footnote1 'Quoting while resolving macro variable "&start3" in the single quotes';
/\ /\ /\
| |inner outer
outer Quote
Thanks
Try it and let us know. :smileygrin:
OOPS ,
I am sorry.
That was an outer double quote with no need of quotes for the macro variables as highlighted!!!!!
line "Report Period from &start3 to &end3";
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.