BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aayushi_17
Quartz | Level 8

Hi i have variable names which have common variable like _high_va and _low_va like this 

SODIUM_NHIGH_VAPOTASSIU_NHIGH_VACHLORIDE_NHIGH_VACARBDIOX_NHIGH_VASODIUM_NLOW_VAPOTASSIU_NLOW_VACHLORIDE_NLOW_VACARBDIOX_NLOW_VA 
 5326  3056  

 

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_HIGHPOTASSIU_HIGHCHLORIDE_HIGHCARBDIOX_HIGHSODIUM_LOWPOTASSIU_LOWCHLORIDE_LOWCARBDIOX_LOW
 5326  3056 

please do suggest some alternative for this step.Thanks in advance 

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

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;

View solution in original post

2 REPLIES 2
gamotte
Rhodochrosite | Level 12

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;
andreas_lds
Jade | Level 19

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);
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1058 views
  • 4 likes
  • 3 in conversation