BookmarkSubscribeRSS Feed
heatherml20
Fluorite | Level 6
* Macro Functions: Practice #1 *
75 *******************************/
76
77 %let Fullname=AnTHoNY MilLeR;
78 %Let First=%scan(&fullname, 1);
79 %Let Last=%scan(&fullname, 2);
80
81 %put &=First
82
83 %put %sysfunc(propcase(&First));
ERROR: Open code statement recursion detected.
84
85 %put &=Last
ERROR: Open code statement recursion detected.
86
87 %put %sysfunc(propcase(&Last));
88
89 %put Fullname=&Fullname First=%sysfunc(propcase(&First)) Last=%sysfunc(propcase(&Last));
ERROR: Open code statement recursion detected.
90
91 %put &Fullname;
ERROR: Open code statement recursion detected.
92
93 %put %upcase(&fullname);
ERROR: Open code statement recursion detected.
94
95 %put The current form of the name is &Fullname and the Propercase is
ERROR: Open code statement recursion detected.
96 %sysfunc(propcase(&Fullname));
97
98 %put _user_;
ERROR: Open code statement recursion detected.
99
100 %symdel Fullname ;
ERROR: Open code statement recursion detected.
101
11 REPLIES 11
antonbcristina
SAS Super FREQ

Hi @heatherml20, I noticed that you're missing semicolons after some of your %PUT statements.  

 

%put &=First

That can cause the errors you're encountering. Try going through your code, add all of the required semicolons to end each statement and rerun. 

heatherml20
Fluorite | Level 6
Hi,

Yes, I found that I missed a couple of semicolons. I appreciate your
help. The main problem is that I did not use a %Mend statement at the end
of the Macro definition.

How do I use a %symdel statement to delete variables from the global symbol
table? How do I show the variables in the table itself?
Tom
Super User Tom
Super User

Usually you don't need to delete macro variables.  They will disappear when your current SAS session ends.  But to delete macro variable just list its name in the %SYMDEL statement.

%symdel x;

To see what is in the GLOBAL symbol table you can use special keyword _GLOBAL_ with the %PUT statement.

%put _global_;

Example::

1    %let x=101;
2    %let y=102;
3    %put _global_;
GLOBAL X 101
GLOBAL Y 102
4    %symdel x ;
5    %put _global_;
GLOBAL Y 102
antonbcristina
SAS Super FREQ

To display in the LOG all macro variables stored, you can use a %PUT statement with the keyword _ALL_ to display all macro variables or _USER_ to display user defined macro variables. 

%put _all_;

%put _user_;

 

To delete macro variables created, you can use the %SYMDEL statement with the name of the macro variable:

%symdel <macro_var_name>;

 

FreelanceReinh
Jade | Level 19

This is how your log would have looked like, had you submitted your code as part of a macro definition (using the macro name test for demonstration):

76    %macro test;
77      %let Fullname=AnTHoNY MilLeR;
78      %Let First=%scan(&fullname, 1);
79      %Let Last=%scan(&fullname, 2);
80
81      %put &=First
82
83      %put %sysfunc(propcase(&First));
ERROR: Macro keyword PUT appears as text.
ERROR: A dummy macro will be compiled.
84
85      %put &=Last
86
87      %put %sysfunc(propcase(&Last));
ERROR: Macro keyword PUT appears as text.
...

But you did not show any of the above error messages, which indicates that you did not submit a macro definition and hence don't need a %MEND statement.

heatherml20
Fluorite | Level 6
The mend statement did get rid of the ERROR: Open code state recursion
detected in this case.
FreelanceReinh
Jade | Level 19

Oh yes, you're right. The %MEND statement helps at least in this particular example (as does submitting the two forgotten semicolons) -- but not because it was missing in the first place.

 

A %MEND statement is also part of the "magic" string that is recommended as a remedy in situations where the reason of the "open code statement recursion" is less obvious. The usage of this string

*'; *"; *); */; %mend; run;

is documented in the section "Solving Open Code Statement Recursion Problems" of the Macro Language Reference, together with other recommendations.

heatherml20
Fluorite | Level 6
Thank you Jade! I appreciate your help\\\ More to come as I am studying
for the Adv 9.4 programming now.
FreelanceReinh
Jade | Level 19

@antonbcristina wrote:

Try going through your code, add all of the required semicolons to end each statement and rerun. 


... and before you rerun the statements which failed, submit the two missing semicolons alone. This should get the macro processor out of that "statement recursion" mode.

;;
heatherml20
Fluorite | Level 6
I did that but I also did not use a %mend statement. I think that is the
error.
FreelanceReinh
Jade | Level 19

A %MEND statement would end the definition of a SAS macro (starting with a %MACRO statement -- which is neither shown in your log, nor required for the %LET, %PUT and %SYMDEL statements to work).

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 3010 views
  • 4 likes
  • 4 in conversation