Hi,
I have a dataset with many variables, named as it follows:
street_density, landuse_mix, street_connectivity, deprivation
I would like to automatically rename them as
x1= street_density, x2=landuse_mix, x3=street_connectivity, x4=deprivation.
I am looking for an easy way to do this for many variables simultaneously.
Thanks!
The reason I asked you to post the proc standard code that you ran is because you can copy the variable list it contains into a data step, then use the proc sql method I mentioned earlier this afternoon. Here is an example using sashelp.class:
PROC STANDARD DATA= sashelp.class MEAN=0 STD=1 OUT=zscoreswk; VAR age height weight; run; data need; input; _n_=1; do while (scan(_infile_,_n_) ne ''); var=scan(_infile_,_n_); output; _n_+1; end; cards; age height weight ; proc sql noprint; select catt(var,'=z_',var) into :vars separated by ' ' from need ; quit; data zscoreswk; set zscoreswk; rename &vars.; run;
HTH,
Art, CEO, AnalystFinder.com
I thought this was what you were asking in the first place. Please post the actual proc standard code that you ran.
Art, CEO, AnalystFinder.com
The reason I asked you to post the proc standard code that you ran is because you can copy the variable list it contains into a data step, then use the proc sql method I mentioned earlier this afternoon. Here is an example using sashelp.class:
PROC STANDARD DATA= sashelp.class MEAN=0 STD=1 OUT=zscoreswk; VAR age height weight; run; data need; input; _n_=1; do while (scan(_infile_,_n_) ne ''); var=scan(_infile_,_n_); output; _n_+1; end; cards; age height weight ; proc sql noprint; select catt(var,'=z_',var) into :vars separated by ' ' from need ; quit; data zscoreswk; set zscoreswk; rename &vars.; run;
HTH,
Art, CEO, AnalystFinder.com
Here's an example of renaming, using the sashelp library. I've broken it out into more steps that ideally necessary, but it helps you to understand what's happening. You can combine steps as you're comfortable with the program.
data class;
set sashelp.class;
run;
data names;
set sashelp.vcolumn;
where libname='SASHELP' and memname='CLASS';
new_name = catt("X", _n_);
keep new_name name;
run;
proc sql noprint;
select catx("=", name, new_name) into :rename_list separated by " "
from names;
quit;
proc datasets lib=work nodetails nolist;
modify class;
rename &rename_list;
run;quit;
Thank you both, Reeza and Art! Your responses are both very helpful! Have a nice afternoon!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.