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

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.

 

 

slchen
Lapis Lazuli | Level 10
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;
vraj1
Quartz | Level 8

Thanks, But i want to replace the values coming from val to the tm.

Jagadishkatam
Amethyst | Level 16
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;
Thanks,
Jag
Steelers_In_DC
Barite | Level 11

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 19 replies
  • 3297 views
  • 3 likes
  • 6 in conversation