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

 

Hello,

 

I need to find the ID where the first 3 characters of the field are between (‘A’) and (‘Z’)...So if I have this list:

 

5021060
A310603
D1A5421
5022000
5001050
5002000
5010020
5010045
5010045
50A5421
5012060
5013100

then the SAS program would output only these:

 

A310603

D1A5421

50A5421

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

something like this

data have;
input string $;
datalines;
5021060
A310603
D1A5421
5022000
5001050
5002000
5010020
5010045
5010045
50A5421
5012060
5013100
501310D
;

data want;
set have;
if anyalpha(substr(string,1,3)) gt 0;
run;

View solution in original post

2 REPLIES 2
kiranv_
Rhodochrosite | Level 12

something like this

data have;
input string $;
datalines;
5021060
A310603
D1A5421
5022000
5001050
5002000
5010020
5010045
5010045
50A5421
5012060
5013100
501310D
;

data want;
set have;
if anyalpha(substr(string,1,3)) gt 0;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep!

Something like (and not tested as not typing all that in):

data want;
  set have;
  if lengthn(compress(substr(yourvar,1,3),"","ka")) > 0 then output;
run;

So take the first 3 chars, compress down to only a-z and if length > 0 at least one is present

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 360 views
  • 0 likes
  • 3 in conversation