BookmarkSubscribeRSS Feed
chouchou
Calcite | Level 5

%macro location(type);

     data _null_;

     call symput('type','Train');

run;

%mend;

%put &type;

%location(Automobile)

%put &type;

Two similar warnings come out:WARNING: Apparent symbolic reference TYPE not resolved.

I think the first %put &type; should resolve to Train; the second %put &type; should resolve to Automobile.

Could anyone explain to me why I am totally wrong? Thank you guys.

2 REPLIES 2
data_null__
Jade | Level 19

Maybe this is what you are trying to do.  But it doesn't seen to have a point.

%macro location(type);
   data _null_;
      call symputx(
'type',"&type",'G');
      run;
  
%mend;
%
location(Auto);
%put NOTE: &=type;
Quentin
Super User

It's all about scoping rules.

Macro variables are stored in symbol tables.  There is a global symbol table (used for the whole SAS session), and a macro can create a local symbol table which exists while the macro is executing.

Your macro creates a local symbol table to hold the parameter (macro variable) TYPE.  When CALL SYMPUT executes and writes the value TRAIN to a macro variable TYPE, it needs to decide whether to write it to the local macro variable that exists named TYPE, or to the global symbol table.  The scoping rules CALL SYMPUT follows tell it to write the the macro variable TYPE in the local symbol table. 

Your %PUT statements outside of the macro don't resolve, because they are looking for a macro variable named TYPE in the global symbol table.  And there isn't one.

data_null_'s solution explicitly tells SYMPUTX to write the macro variable TYPE to the global symbol table, accomplishing your apparent purpose.

--Q.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

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
  • 2 replies
  • 583 views
  • 0 likes
  • 3 in conversation