BookmarkSubscribeRSS Feed
Saikiran_Mamidi
Obsidian | Level 7

data have;
input names$;
cards;
12345a
1653537d
14252d
425f52a
58463e
run;

this is data i have,but i want only data having 5digits and 1char
i want data like this from above data

12345a
14252d
58463e

code and explanation please?

1 REPLY 1
ed_sas_member
Meteorite | Level 14

Hi @Saikiran_Mamidi 

You can use the PRXMATCH function for example:

data want;
	set have;
	if prxmatch('/^\d{5}[a-z]$/',strip(names)) then output;
run;

It looks for the following pattern: ^\d{5}[a-z]$

^ = beginning of the string

\d{5} = 5 digits

[a-z] = one letter (case insensitive -> cf "i" modifier)

$ = end of the string

 

strip()  enables to take into account trailing blanks.

 

 

You could also use:

if prxmatch('/^\d{5}[a-z]\s*$/i',names) then output;

-> \s means a blank and * means 0,1 or more times -> looks for trailing blanks

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!

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
  • 1 reply
  • 352 views
  • 0 likes
  • 2 in conversation