Why are you keeping all your data in one variable to start with? A dataset which looks like this:
TM TEST FLAG GROUP DURATION TIME
DGM_HIGH_IG_DUR24_10_0 DMG H IG 24 10:00
I.e. keep your variable, but split it up into relevant variables, this would be far easier for you to work with. You can split it up simply by a do loop and a scan based of the index variable.
data have;
length tm $ 30;
input tm;
val=34*(input(prxchange('s/.*_(\d+)_(\d)$/$1.$2/',-1,strip(tm)),best12.));
datalines;
DGM_HIGH_IG_DUR24_10_0
CGM_HIGH_IG_DUR24_12_0
CGM_LOW_IG_DUR24_3_5
DGM_HIGH_IG_DUR24_180_2
run;
proc print;
run;
Thanks, But i want to replace the values coming from val to the tm.
data have;
length ex2 $50;
tm="CGM_HIGH_IG_DUR24_182_0";
len=length(tm);
ex='_'||strip(put(input(tranwrd(substr(tm,prxmatch('m/\_\d/',tm)+1),'_','.'),best.)*34,best.))||'_0';
ex2=cats(prxchange('s/\_\d*\_\d//',1,tm),ex);
run;
Here is a solution:
data have;
input variable $25.;
cards;
DGM_HIGH_IG_DUR24_10_0
CGM_HIGH_IG_DUR24_12_0
CGM_LOW_IG_DUR24_3_5
;
data want;
set have;
variable = catx('.',scan(variable,5,'_'),scan(variable,6,'_')) * 34;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.