BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASMom2
Fluorite | Level 6

I need help to exclude records with a variable that has values other than numbers and characters. Below is an example.

 

I have a variable 'test' which has values like below.

 

Test
00*915174
00*915174
(00)-1234
00(9151.74)
00_915_174
00-9151-74
001234

 

In the above column, I would like to exclude all the values with special character such as (, ), -, ., * and space. I want to keep values such as '001234' or 'ABC123'.

 

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
webart999ARM
Quartz | Level 8
data want;
    set have;
    retain re_pattern;
    if _N_ = 1 then re_pattern = prxparse('/^[A-Za-z0-9]+$/');
    if prxmatch(re_pattern, strip(test)) then output;
run;


or

data want;
    set have;
    if not prxmatch('/^[a-zA-Z0-9]+$/', strip(test)) then delete;
run;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

It sounds to me like you could re-phrase the requirements to keep strings which contain digits or numbers, but not anything else.


And so this is a job for the FINDC function.

 

if findc(test,,'kad') then delete;
--
Paige Miller
SASMom2
Fluorite | Level 6

I feel so dumb asking this but still asking...what is 'kad' in your statement.

Thanks

SASKiwi
PROC Star

@SASMom2  - Click on the FINDC documentation link provided by @PaigeMiller and you will find what 'kad' means.

SASMom2
Fluorite | Level 6

Thanks you @SASKiwi 

I figured it out.

Thanks you @PaigeMiller for your suggestion.

 

Ksharp
Super User
data have;
input test $20.;
cards;
00*915174
00*915174
(00)-1234
00(9151.74)
00_915_174
00-9151-74
001234
ABC123
;
data want;
 set have;
 if notalnum(strip(test)) then delete;
run;
webart999ARM
Quartz | Level 8
data want;
    set have;
    retain re_pattern;
    if _N_ = 1 then re_pattern = prxparse('/^[A-Za-z0-9]+$/');
    if prxmatch(re_pattern, strip(test)) then output;
run;


or

data want;
    set have;
    if not prxmatch('/^[a-zA-Z0-9]+$/', strip(test)) then delete;
run;
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
  • 6 replies
  • 1558 views
  • 1 like
  • 5 in conversation