BookmarkSubscribeRSS Feed
Pramod_R
Calcite | Level 5

Hi,

I have a list of macro variables m1,m2,m3... etc each of it having values as given below:

value of &m1 is: name=Pramod

value of &m2 is: location=Bangalore

value of &m3 is: date=29nov2011

.

.

.

I want to convert each of these key value pairs into macro variable-value pairs. That is, I want macro variables and thier values as below:

value of &name is: Pramod

value of &location is: Bangalore

value of &date is : 29nov2011

etc..

Please let me know if you need more clarity on understanding the problem statement..

Thanks in advance!

Pramod

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

Is this what you want?

%let m1 =name=Pramod;

%let m2 =location=Bangalore;

%let m3 = date=29nov2011;

%macro test;

data look;

length mn $ 8 mv $ 12;

%do i=1 %to 3;

mn="%scan(&&m&i,1,'=')";

mv="%scan(&&m&i,2,'=')";

output;

%end;

run;

%mend;

%test

data _null_;

   set look;

   call symputx(mn,mv);

run;

%put _user_;

21   %put _user_;

GLOBAL LOCATION Bangalore

GLOBAL DATE 29nov2011

GLOBAL M1 name=Pramod

GLOBAL M2 location=Bangalore

GLOBAL M3 date=29nov2011

GLOBAL NAME Pramod

Linlin

data_null__
Jade | Level 19

%let m1=name=Pramod;

%let m2=location=Bangalore;

%let m3=date=29nov2011;

*simply;

%let &m1;

%put _user_;

*or automagically;

data _null_;

   set sashelp.vmacro(where=(SCOPE='GLOBAL' and name eq: 'M'));

   put _all_;

   call execute(cat('%let ',strip(value),';'));

   run;

%put _user_;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1591 views
  • 0 likes
  • 3 in conversation