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