Hi i have variable names which have common variable like _high_va and _low_va like this
| SODIUM_NHIGH_VA | POTASSIU_NHIGH_VA | CHLORIDE_NHIGH_VA | CARBDIOX_NHIGH_VA | SODIUM_NLOW_VA | POTASSIU_NLOW_VA | CHLORIDE_NLOW_VA | CARBDIOX_NLOW_VA | |
| 53 | 26 | 30 | 56 |
i would like to change this as
SODIUM_HIGH for SODIUM_NHIGH_VA likewise for SODIUM_NLOW_VA as SODIUM_LOW which is the variable name and it has values
the output should look like this :
| SODIUM_HIGH | POTASSIU_HIGH | CHLORIDE_HIGH | CARBDIOX_HIGH | SODIUM_LOW | POTASSIU_LOW | CHLORIDE_LOW | CARBDIOX_LOW |
| 53 | 26 | 30 | 56 |
please do suggest some alternative for this step.Thanks in advance
Hello,
data _NULL_;
call execute('data want; set have; rename');
do until(lastrow);
set sashelp.vcolumn end=lastrow;
where libname="WORK" and memname="HAVE";
call execute(cats(NAME,'=',tranwrd(NAME,'NHIGH_VA','HIGH')));
end;
call execute('; run;');
stop;
run;
Hello,
data _NULL_;
call execute('data want; set have; rename');
do until(lastrow);
set sashelp.vcolumn end=lastrow;
where libname="WORK" and memname="HAVE";
call execute(cats(NAME,'=',tranwrd(NAME,'NHIGH_VA','HIGH')));
end;
call execute('; run;');
stop;
run;
Using the code @gamotte suggest, i would only change the way the new name is build:
catx('_', scan(Name, 1), substr(scan(Name, 2), 2))
or a regex in prxchange:
prxchange("s/(.+_).(.+)_.*/$1$2/", 1, Name);
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.