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

Hello,

Following is the typical call symput procedure:

data a2;

set a1;

call symput("mvar",xyz);

run;

I want to do the following:

%macro abcd (data=,mvar=);

data a2;

set &data;

call symput("&mvar",xyz)

%mend;

%abcd (data=a0, mvar=mvar0)

%abcd (data=a1, mvar=mvar1);

However, I'm getting error. Can I assign macro variable name within call symput through a local macro? Is there any efficient way to do this?

Thanks,

P

1 ACCEPTED SOLUTION

Accepted Solutions
StatsGeek
SAS Employee

Hi pmesh,

Your current code defines the new macro variables as local macro variables. To use them outside of the macro, just declare them as global macro variables. Changing your code as shown below fixes the problem.

%macro abcd(data=,mvar=);

data a2;

   set &data;

   %global &mvar;

   call symput("&mvar",xyz);

run;

%mend;

%abcd (data=a0, mvar=mvar0);

%abcd (data=a1, mvar=mvar1);

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

This is a untested code, please try

%macro abcd (data=,mvar=);

data a2;

set &data;

call symput("mvar"||strip(&mvar),xyz)

%mend;

%abcd (data=a0, mvar=0);

%abcd (data=a1, mvar=1);

Thanks,

Jag

Thanks,
Jag
pmesh
Calcite | Level 5

Hi Jag,

Thanks for your prompt reply. Unfortunately, it is not working and I'm getting an error saying that the symbolic variable name mvar. must contain only letters, digits, and underscores.

Any possibility of renaming the macro variable created by call symput?

Thanks,

P

StatsGeek
SAS Employee

Hi pmesh,

Your current code defines the new macro variables as local macro variables. To use them outside of the macro, just declare them as global macro variables. Changing your code as shown below fixes the problem.

%macro abcd(data=,mvar=);

data a2;

   set &data;

   %global &mvar;

   call symput("&mvar",xyz);

run;

%mend;

%abcd (data=a0, mvar=mvar0);

%abcd (data=a1, mvar=mvar1);

pmesh
Calcite | Level 5

Thanks a lot Stephen! That worked perfectly!

Ksharp
Super User

Or use the third parameter 'G'.

%macro abcd(data=,mvar=);

data a2;

   set &data;

   call symputx("&mvar",age,'G');

run;

%mend;

%abcd (data=sashelp.class, mvar=mvar0)

%put _global_ ;

Xia Keshan

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3472 views
  • 3 likes
  • 4 in conversation