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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1105 views
  • 1 like
  • 2 in conversation