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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 945 views
  • 1 like
  • 4 in conversation