## how to split the below word

Solved
Regular Contributor
Posts: 214

# how to split the below word

i have a variable called tm. It has character values like "DGM_HIGH_IG_DUR24_10_0" and "CGM_HIGH_IG_DUR24_12_0" and "CGM_LOW_IG_DUR24_3_5".

I want to extract _10_0 from first and _12_0 and _3_5 from second and third and calculate 10.0*34 and 12.0*34 and 3.5*34 and replace the value with the ealier ones.

Can anyone help me in this please

Accepted Solutions
Solution
‎11-13-2015 09:34 AM
Posts: 1,147

## Re: how to split the below word

``````data have;
length ex2 \$50;
tm="CGM_HIGH_IG_DUR24_182_8";
len=length(tm);
dec=scan(put(input(tranwrd(substr(tm,prxmatch('m/\_\d/',tm)+1),'_','.'),best.)*34,best.),2,'.');
if dec=. then ex='_'||strip(put(input(tranwrd(substr(tm,prxmatch('m/\_\d/',tm)+1),'_','.'),best.)*34,best.))||'_0';
else if dec^=. then ex='_'||tranwrd(strip(put(input(tranwrd(substr(tm,prxmatch('m/\_\d/',tm)+1),'_','.'),best.)*34,best.)),'.','_');
ex2=cats(prxchange('s/\_\d*\_\d//',1,tm),ex);
run;``````
Thanks,
Jag

All Replies
Valued Guide
Posts: 574

## Betreff: how to split the below word

[ Edited ]

Using the functions scan and input:

```data work.have;
length tm \$ 30;
input tm;
datalines;
DGM_HIGH_IG_DUR24_10_0
CGM_HIGH_IG_DUR24_12_0
CGM_LOW_IG_DUR24_3_5
run;

data work.want;
set work.have;

length result 8;

result = 34 * (input(scan(tm, 2, '_', 'b'), best32.) + input(scan(tm, 1, '_', 'b'), best32.) / 10);
run;```
Regular Contributor
Posts: 214

## Betreff: how to split the below word

Thanks a lot

Can i replace the new values i.e result values with the old ones for example if i get 180.2 i need to replace it

`DGM_HIGH_IG_DUR24_180_2How can i do that please?`

Posts: 1,147

## Re: how to split the below word

``````data want;
set have;
len=length(tm);
ex=input(tranwrd(substr(tm,len-3),'_','.'),best.)*34;
run;``````
Thanks,
Jag
Posts: 1,147

## Re: how to split the below word

Please try the below which` will work `

`data want; set have; len=length(tm); ex=input(tranwrd(prxchange('s/^\_//',1,substr(x,len-3)),'_','.'),best.)*34; run;`

Thanks,
Jag
Regular Contributor
Posts: 214

## Re: how to split the below word

it is not working.

Variable x is uninitialized.
NOTE: Invalid second argument to function SUBSTR at line 1

Posts: 1,147

## Re: how to split the below word

Sorry

try this

``````data want;
set have;
len=length(tm);
ex=input(tranwrd(prxchange('s/^\_//',1,substr(tm,len-3)),'_','.'),best.)*34;
run;``````
Thanks,
Jag
Regular Contributor
Posts: 214

## Re: how to split the below word

Thanks. This is coming for me but i want to replace the new values with the old one.

for ex: CGM_HIGH_IG_DUR24_10_0 and ex value for this is 180.2 then it needs to be CGM_HIGH_IG_DUR24_180_2

Posts: 1,147

## Re: how to split the below word

Could you please explain what you mean by the earliest value like if you see the earliest values from 10*34, 12*34 and 3.5*34 is 119 which is from 3.5*34. There is a confusion here to understand the earliest value
Thanks,
Jag
Regular Contributor
Posts: 214

## Re: how to split the below word

yes for example i have a value in tmp called CGM_HIGH_IG_DUR24_10_0 and after calculation i.e 10.0*18=180.0 then i need to replace CGM_HIGH_IG_DUR24_10_0 to CGM_HIGH_IG_DUR24_180_0.

Hope you got it

Posts: 1,147

## Re: how to split the below word

yes thank you i tried the same, hope it will help you
Thanks,
Jag
Regular Contributor
Posts: 214

## Re: how to split the below word

Here there is a small catch. if the value is  132.6 then it should come as 132_6 but we are getting CGM_LOW_IG_DUR24_132.6_0

Solution
‎11-13-2015 09:34 AM
Posts: 1,147

## Re: how to split the below word

``````data have;
length ex2 \$50;
tm="CGM_HIGH_IG_DUR24_182_8";
len=length(tm);
dec=scan(put(input(tranwrd(substr(tm,prxmatch('m/\_\d/',tm)+1),'_','.'),best.)*34,best.),2,'.');
if dec=. then ex='_'||strip(put(input(tranwrd(substr(tm,prxmatch('m/\_\d/',tm)+1),'_','.'),best.)*34,best.))||'_0';
else if dec^=. then ex='_'||tranwrd(strip(put(input(tranwrd(substr(tm,prxmatch('m/\_\d/',tm)+1),'_','.'),best.)*34,best.)),'.','_');
ex2=cats(prxchange('s/\_\d*\_\d//',1,tm),ex);
run;``````
Thanks,
Jag
Regular Contributor
Posts: 214

## Re: how to split the below word

Thanks a lot

Super Contributor
Posts: 275

## Re: how to split the below word

``````data have;
length tm \$ 30;
input tm;
val=prxchange('s/.*_(\d+?.?\d?)_(\d)\$/\$1.\$2/',-1,strip(tm));
if count(val,'.')>1 then val=prxchange('s/(.*).(\d)\$/\$1\$2/',-1,strip(val));
val=34*(input(val,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
CGM_LOW_IG_DUR24_132.6_0
;
run;
proc print;
run;``````

with CGM_LOW_IG_DUR24_132.6_0 in data set.

🔒 This topic is solved and locked.