BookmarkSubscribeRSS Feed
Super User Tom
Super User

@Shmuel wrote:

@Tom may I ask, suppose you have a macro program in a macro program:

/* %let choice = xxx; -- either exists as global or does not exits */

%macro main;
   %local choise;

%macro called(...arguments ...);
    %global choice;
     %if  %symexist(choice) %then ... ;


in such case which macro variable CHOICE shall %symexist() check - the %local or the %global ?

So that is the combination will generate an error message. When the sub-macro CALLED starts and tries to create a global symbol named CHOICE it will issue an error message since CHOICE already exists in the symbol table for the MAIN macro.


We are essentially trying to deal with what I call "external" macro variables.  They are not defined as parameters to the macro or defined as local macro variables that the macro uses for its own purpose.  The reference to them just seems to appear in the code and how they are supposed to have ever gotten assigned a value is magic of some type. 


Here is the general pattern I would follow.

1) Test if the macro variable exists or not and then create it in the appropriate scope.

2) Test if the macro variable is populated or not and if appropriate assign it a default value (or take appropriate action for when the value is empty.).

%macro called(...arguments ...);
    %if not %symexist(choice) %then %local choice;
    %if 0=%length(%superq(choice)) %then ... ;


Garnet | Level 18

Thanks @Tom , you absolutely clarified the point.

Quartz | Level 8

Thanks to everyone for their help. I wasn't able to get the code to work like I wanted so I changed other parts of the code to solve the problem. 


Thanks again

Calcite | Level 5



It pretty much simple.


data check_var;
if varname_ >0 then flag="Y"; else flag="N";
/* if flag="Y";*/


** If you want to create a macro then use the below code .

data _NULL_;
call symputx("Checkv", varnum(open("sashelp.class"),'AGE'));
%put &Checkv.;


Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


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
  • 18 replies
  • 4 in conversation