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

Hi folks - it could seems a silly question.

 

I have a varlist as a result of macroA.

%macroA;

...

%put &varlist;

%mend;

 

I need to use the created varlist in macroA in macroB as input.

but SAS errors me that &varlist is not recognised.

 

please help me in this regard....

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The issue is variable scope. 

A macro variable created within a macro, is local, it only exists within the macro. To use the macro variable outside of the macro you need to change the scope to global, as someone has already indicated.

 

%global varlist;

 

If you're creating a macro variable using call symput, change to call symputx and use the -g option.

 

 

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16
Could you please let us know how you are using the &varlist in macro B. Is the macro variable &varlist resolving
Thanks,
Jag
Astounding
PROC Star

Within %macroA, add this statement early:

 

%global varlist;

 

That will keep it around after %macroA ends.

 

 

Reeza
Super User

The issue is variable scope. 

A macro variable created within a macro, is local, it only exists within the macro. To use the macro variable outside of the macro you need to change the scope to global, as someone has already indicated.

 

%global varlist;

 

If you're creating a macro variable using call symput, change to call symputx and use the -g option.

 

 

gamotte
Rhodochrosite | Level 12

Apart from using globals, you can make each call of the macro to be substituted

by the variables list as follows :

 

%macro macroA;

     /* Code to generate the list */

     [...]

 

     &varlist

 

%mend macroA;

 

%macro macroB;

 

    %let variables=%macroA;

    [...]

%mend macroB;

 

Moh
Obsidian | Level 7 Moh
Obsidian | Level 7

thanks...

sas-innovate-2024.png

📢

ANNOUNCEMENT

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1245 views
  • 0 likes
  • 5 in conversation