BookmarkSubscribeRSS Feed
deleted_user
Not applicable
dear all,

When I use the following code to rename a variable name, it works well.

proc means median maxdec=2 data=tmp;
var x1;
class group;
ods output summary=tmp1;
data tmp1;set tmp1(rename=x_median=xmedian);
run;

When I use a following macro to rename the variable name, it doesn't work any way.

%macro rename(data=,var=,group=);
proc means median maxdec=2 data=&data;
var &var;
class &group;
ods output summary=tmp1;
data tmp1;set tmp1(rename=&&var_median=xmedian);
run;
%mend;

How can I to revise the macro? Thanks in advance for your time and patience.
4 REPLIES 4
RickM
Fluorite | Level 6
It looks like the problem is most likely because SAS thinks &var_median is a macro variable (as in %let var_median=Variable; ). You need a period at the end of your macro variable so that SAS will look up the correct macro variable name. It also looks like the && is redundant in your code.

So try using:

set tmp1(rename=&var._median=xmedian);
deleted_user
Not applicable
Many thanks for your help. I have tried to replace the &var_median with &var._median or &&var_median, but sas doesn't work.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest the OP post a reply with the SAS log revealing the exact error so we can better understand what this means: "sas doesn't work"

Scott Barry
SBBWorks, Inc.
statsplank
Calcite | Level 5
Hi wmqy,

Does the variable in tmp1 must be xmedian? Can it be medianx?

If medianx is ok, try the following code:

%macro rename(data=,var=,group=);
proc means maxdec=2 data=&data noprint;
var &var;
class &group;
output out=tmp1 median(&var)=median&var;
run;
data tmp1;
set tmp1(where=(_Type_ NE 0));
drop _Type_ _Freq_;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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