macro name is output of %scan function

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

macro name is output of %scan function

Hi,

How can I refer the macro whose name is the output of %scan function? For example, I have a macro of

%let macro1 = 1;

%let macro2 = 2;

%let macro3 = 3;

%let macro_all = macro1 macro2 macro3

Can I use something like

&%scan(&macro_all, 1, %str())  to get the value of 1?  Thanks.


Accepted Solutions
Solution
‎02-13-2014 03:17 PM
Super User
Posts: 17,731

Re: macro name is output of %scan function

I still think you need to provide more info on how you plan to use it, but the following will allow the macro variable to resolve. There are probably other ways.

%let macro1 = 1;

%let macro2 = 2;

%let macro3 = 3;

%let macro_all = macro1 macro2 macro3;

%let test=%scan(&macro_all, 1);

%put &&&test;

View solution in original post


All Replies
Super User
Posts: 17,731

Re: macro name is output of %scan function

I think it partly depends on where you want to use the value of 1.

Where are you trying to get the macro variable to resolve, in the path of file, middle of a macro, data step?

Contributor
Posts: 36

Re: macro name is output of %scan function

Thank you Reeza. I want to use the value of 1 in the middle of a macro. thanks.

Solution
‎02-13-2014 03:17 PM
Super User
Posts: 17,731

Re: macro name is output of %scan function

I still think you need to provide more info on how you plan to use it, but the following will allow the macro variable to resolve. There are probably other ways.

%let macro1 = 1;

%let macro2 = 2;

%let macro3 = 3;

%let macro_all = macro1 macro2 macro3;

%let test=%scan(&macro_all, 1);

%put &&&test;

Contributor
Posts: 36

Re: macro name is output of %scan function

It works! Thank you so much!

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 245 views
  • 0 likes
  • 2 in conversation