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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 2383 views
  • 3 likes
  • 4 in conversation