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

Which title statement will be printed as a result of the SAS code shown below?

a.jpg
Listing of MTEST Macro VariablesListing of Macro Variables    Listing of GLOBAL Macro VariablesListing of &val3 Macro VariablesThere is no title because the code produces an error in the log.


According to me Local symbol table has Va13=MTEST macro variable once it finishes execution local symbol table gets deleted and only global symbol table remains so The correct ans would be " Listing of GLOBAL Macro Variables "??

1 ACCEPTED SOLUTION

Accepted Solutions
Vish33
Lapis Lazuli | Level 10

Hi,

As you mentioned Local symbol table has val3=MTEST and the scope variable in proc print will be having the scope of MTEST only , not GLOBAL because the global macro variable will be overwritten with local macro variable if it is with same name..I took a sample data and checked which might help you.

%let val3=GLOBAL;

data test;

input var $ scope $;

cards;

var1 LOCAL

var2 GLOBAL

var3 LOCAL

;

run;

options symbolgen;

%macro mtest(val1,val2,val3=MTEST);

title "Listing of &val3 Macro Variables";

proc print data=&val1;

where scope="&val3";

Var &val2;

run;

%mend;

%mtest(test,var); /* This macro returns val3=MTEST only */

%mtest(test,var,val3=&val3); /* here i have declared val3 will take the global macro variable value as GLOBAL */

PLease find the snapshot for the below macro output.

global.jpg

View solution in original post

3 REPLIES 3
Vish33
Lapis Lazuli | Level 10

Hi,

As you mentioned Local symbol table has val3=MTEST and the scope variable in proc print will be having the scope of MTEST only , not GLOBAL because the global macro variable will be overwritten with local macro variable if it is with same name..I took a sample data and checked which might help you.

%let val3=GLOBAL;

data test;

input var $ scope $;

cards;

var1 LOCAL

var2 GLOBAL

var3 LOCAL

;

run;

options symbolgen;

%macro mtest(val1,val2,val3=MTEST);

title "Listing of &val3 Macro Variables";

proc print data=&val1;

where scope="&val3";

Var &val2;

run;

%mend;

%mtest(test,var); /* This macro returns val3=MTEST only */

%mtest(test,var,val3=&val3); /* here i have declared val3 will take the global macro variable value as GLOBAL */

PLease find the snapshot for the below macro output.

global.jpg

poo
Calcite | Level 5 poo
Calcite | Level 5

Thank you Vish33 very much, I have exam tomorrow I was lil confuse with that question.

Vish33
Lapis Lazuli | Level 10

welcome Poo..All the best

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
  • 3 replies
  • 1058 views
  • 1 like
  • 2 in conversation