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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 557 views
  • 0 likes
  • 2 in conversation