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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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