BookmarkSubscribeRSS Feed
GeorgeSAS
Lapis Lazuli | Level 10

Hello everyone,

 

I want rename multiple varaibles (they have common begin characters var_)in data three, but not work,please help.

 

data one;

var_1=1;var_2=2;var_3=3;var_4=4; var5=5;output;

run;

 

 

data two;

set one;

rename var_3=var_3_new;

*rename var_:=varname(var_:  )||_new;

run;

 

data three;

set one;

rename var_:=varname(var_:  )||_new;/*this not work*/

run;

 

Thanks!

2 REPLIES 2
Reeza
Super User

The rename only takes text, you can't use functions like that. You need to list all out. 

 

If if you have a series with common prefix you can do the following:

 

rename x1-x5 = new_x1-new_x5;

 

Use prefixes rather than suffixes to make your life easier. 

Ksharp
Super User
You could create a map file to describe how to rename these variables.




data one;
var_1=1;var_2=2;var_3=3;var_4=4; var5=5;output;
run;

proc transpose data=one(obs=0) out=temp;
var _all_;
run;

data temp;
 set temp;
 new=catx('_',_name_,'new');
run;

data _null_;
 set temp end=last;
 if _n_=1 then call execute('proc datasets lib=work nolist nodetails;modify one;rename ');
 call execute(catx('=',_name_,new));
 if last then call execute(';quit;');
run;

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
  • 780 views
  • 2 likes
  • 3 in conversation