BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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:

http://www.sascommunity.org/wiki/Split_Data_into_Subsets

View solution in original post

8 REPLIES 8
Reeza
Super User

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:

http://www.sascommunity.org/wiki/Split_Data_into_Subsets

robertrao
Quartz | Level 8

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;

Reeza
Super User

No you're not right.

See the documentation for examples of usage.

SAS(R) 9.2 Macro Language: Reference

robertrao
Quartz | Level 8

Thanks for the help.

Tom
Super User Tom
Super User

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.

robertrao
Quartz | Level 8

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

Tom
Super User Tom
Super User

Try it and let us know. :smileygrin:

robertrao
Quartz | Level 8

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";

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1117 views
  • 6 likes
  • 3 in conversation