Help using Base SAS procedures

Need macro to resolve to macro name

Accepted Solution Solved
Reply
SAS Employee
Posts: 4
Accepted Solution

Need macro to resolve to macro name

Hey does anyone know how to resolve &Key to &animal (or animal) and not platypus and not key?

12   %let animal = platypus;

13   %let key = &animal.;

14

15   %put %str(&key.);

platypus

16   %put %nrstr(&key.);

&key.


Accepted Solutions
Solution
‎05-12-2015 08:58 AM
Super User
Posts: 9,681

Re: Need macro to resolve to macro name

%let animal = platypus;

%let key = %nrstr(&animal.);

%put &key;

View solution in original post


All Replies
Super User
Super User
Posts: 6,500

Re: Need macro to resolve to macro name

Not sure what you mean.

If you want &KEY to resolve to animal then set it to animal.

%let key=animal ;

If you want include macro trigger in the value then quote the trigger.  Your attempt with %STR(&animal) is quoting the result of the macro variable expansion.

%let key=%str(&)animal ;

Super User
Super User
Posts: 7,401

Re: Need macro to resolve to macro name

The question from me would be why? 

Solution
‎05-12-2015 08:58 AM
Super User
Posts: 9,681

Re: Need macro to resolve to macro name

%let animal = platypus;

%let key = %nrstr(&animal.);

%put &key;

SAS Employee
Posts: 4

Re: Need macro to resolve to macro name

Ahhh thank you Xia.   This will work for what we need.

Inheriting large complicated programs is not much fun. 

To all, thank you for responding.  

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 230 views
  • 0 likes
  • 4 in conversation