Help using Base SAS procedures

How to use a created &varlist in %macroA in %macroB

Accepted Solution Solved
Reply
Contributor Moh
Contributor
Posts: 20
Accepted Solution

How to use a created &varlist in %macroA in %macroB

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....


Accepted Solutions
Solution
‎01-11-2016 06:55 AM
Super User
Posts: 19,770

Re: How to use a created &varlist in %macroA in %macroB

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


All Replies
Trusted Advisor
Posts: 1,137

Re: How to use a created &varlist in %macroA in %macroB

Could you please let us know how you are using the &varlist in macro B. Is the macro variable &varlist resolving
Thanks,
Jag
Super User
Posts: 5,497

Re: How to use a created &varlist in %macroA in %macroB

Within %macroA, add this statement early:

 

%global varlist;

 

That will keep it around after %macroA ends.

 

 

Solution
‎01-11-2016 06:55 AM
Super User
Posts: 19,770

Re: How to use a created &varlist in %macroA in %macroB

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.

 

 

Regular Contributor
Posts: 233

Re: How to use a created &varlist in %macroA in %macroB

[ Edited ]

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;

 

Contributor Moh
Contributor
Posts: 20

Re: How to use a created &varlist in %macroA in %macroB

thanks...

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 437 views
  • 0 likes
  • 5 in conversation