BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi, 

I have a dataset

ID

2000032

2000072

2000092

I want the dataset:

ID

0003

0007

0009

I want to remove first 2digits and last one digit.

Can anyone help in this. thank you

3 REPLIES 3
PaigeMiller
Diamond | Level 26

It's hard to generalize from such a small example. Are there always two digits at the start and always one digit at the end? Are the strings always 7 characters? It seems as if all you want is characters 3 4 5 and 6, so this code will work:

 

new_id=substr(id,3,4);
--
Paige Miller
Ksharp
Super User
data have;
input ID $;
want=prxchange('s/^\d\d|\d\s*$//',-1,id);
cards;
2000032
2000072
2000092
;
Kurt_Bremser
Super User
data have;
input ID $;
datalines;
2000032
2000072
2000092
;

data want;
set have;
id = substr(id,3,4);
run;

This code might nicely illustrate that your question suffers from a Maxim 42 issue.