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);
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.