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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 718 views
  • 1 like
  • 4 in conversation