BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sami1234
Fluorite | Level 6

Hi All,

 

I have a couple of macro variables in my SAS code which contains the list of variables. i.e.

%let  list1= var1 var2 var3 var4 ........ ;
%let list2= var10 var15 var60 ;        (few variables from list1)
%let  uplist1=%upcase(%str(&list1.));
%let  uplist2=%upcase(%str(&list2.));

When I run the above code, I am getting the error Open code statement recursion detected'

Is there any way to remove it, please?

 

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Sami1234 wrote:

 

Hi All,

 

I have a couple of macro variables in my SAS code which contains the list of variables. i.e.

 

%let  list1= var1 var2 var3 var4 ........ ;

%let list2= var10 var15 var60 ;        (few varaibles from list1)

%let  uplist1=%upcase(%str(&list1.));

%let  uplist2=%upcase(%str(&list2.));

 

When I run the above code, I am getting the error Open code statement recursion detected'

Is there any way to remove it, please?

 

Thank you!

 


Since the only reason you would need to use %str in

%let  uplist1=%upcase(%str(&list1.));

%let  uplist2=%upcase(%str(&list2.));

would be the inclusion of special characters of some sort then perhaps you need to show the entire list of actual values for List1 and list2

Example:

%let list1= var1 var2 var3 var4 ........ ;

%let uplist1=%upcase(&list1.);

%put &uplist1.;

As soon as you start placing other than simple text into your variable then the actual text matters, especially if it includes macro triggers like & or % (in which case you may need %NRSTR instead of %str)

 

Note that a missing ; on a let statement might be place to start as this will duplicate the error:

2965  %let list1= var1 var2 var3 var4 ........
2966
2967  %let uplist1=%upcase(&list1.);
ERROR: Open code statement recursion detected.


View solution in original post

7 REPLIES 7
Patrick
Opal | Level 21

@Sami1234 

This error indicates that you've got a syntax error somewhere in your macro code -  a missing semicolon for example. The code you've posted looks o.k. though.

Reeza
Super User
I would expect to a %IF/%THEN or something else that may generate that but nothing in your code appears problematic. Run each line at a time to find the actual error.
ballardw
Super User

@Sami1234 wrote:

 

Hi All,

 

I have a couple of macro variables in my SAS code which contains the list of variables. i.e.

 

%let  list1= var1 var2 var3 var4 ........ ;

%let list2= var10 var15 var60 ;        (few varaibles from list1)

%let  uplist1=%upcase(%str(&list1.));

%let  uplist2=%upcase(%str(&list2.));

 

When I run the above code, I am getting the error Open code statement recursion detected'

Is there any way to remove it, please?

 

Thank you!

 


Since the only reason you would need to use %str in

%let  uplist1=%upcase(%str(&list1.));

%let  uplist2=%upcase(%str(&list2.));

would be the inclusion of special characters of some sort then perhaps you need to show the entire list of actual values for List1 and list2

Example:

%let list1= var1 var2 var3 var4 ........ ;

%let uplist1=%upcase(&list1.);

%put &uplist1.;

As soon as you start placing other than simple text into your variable then the actual text matters, especially if it includes macro triggers like & or % (in which case you may need %NRSTR instead of %str)

 

Note that a missing ; on a let statement might be place to start as this will duplicate the error:

2965  %let list1= var1 var2 var3 var4 ........
2966
2967  %let uplist1=%upcase(&list1.);
ERROR: Open code statement recursion detected.


Sami1234
Fluorite | Level 6

Thank you so much for your reply!

Actually, it's not throwing any error or warning now by using the following code, running  within the macro

 

 

%let  list1= var1 var2 var3 var4 ........ ;

%let list2= var10 var15 var60 ;        (few varaibles from list1)

%let  uplist1=%unquote(%upcase(%str(&list1.)));

%let  uplist2=%unquote(%upcase(%str(&list2.)));

carl_sommer
SAS Employee
@Sami1234 has nailed it. At some point in your SAS session, the macro processor attempted to process what you thought was simple text, but to the processor, required resolution. This is why in a new session you couldn't make the error appear from the code that was correct; most likely the "open" issue was created prior to that.

Prior to 9.4 M5, %IF %THEN %ELSE was a common culprit of this, as it had to be inside a macro. For information on this restriction being lifted, see https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/
Astounding
PROC Star
So you now have all the clues you need to solve this. I'll give you 30 minutes to work it out before I post again.
Astounding
PROC Star
When you ran the code originally, you ran it outside of any macros. At the time, there were earlier SAS statements that had a missing semicolon.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7 replies
  • 43732 views
  • 3 likes
  • 6 in conversation