There are some variables that end in "zz". How to rename only those variables by removing "zz" from variable name?
For example Temperaturezz should be renamed to Temperature.
And you want to do so for all variables in a specific data set?
Yes. Most of the variables end with "zz" so would like to remove zz and those without zz Would like to keep them as is
Ok. Here is one way
data test;
input onezz two threezz;
datalines;
1 2 3
;
data _null_;
set sashelp.vcolumn end=lr;
where libname='WORK' and memname='TEST';
if _n_ = 1 then
call execute('proc datasets lib=work nolist; modify test;');
if substr(name,length(name)-1,2)='zz' then
call execute(compbl(cat('rename ', name, '=', tranwrd(name, 'zz', ''), ';')));
if lr then call execute('quit;');
run;
Looks good, but you probably will want to tighten up the logic.
Make sure test for names that end in ZZ or zZ or Zz also.
lowcase(substr(name,length(name)-1,2))='zz'
Also you don't want to remove the zz from the middle of a name like PIzzazz.
call execute(catx(' ','rename',name,'=',substr(name,1,length(name)-2)))
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.