DATA Step, Macro, Functions and more

prxmatch / all character, all numeric or any alphanumeric

Accepted Solution Solved
Reply
Super Contributor
Posts: 331
Accepted Solution

prxmatch / all character, all numeric or any alphanumeric

I'm trying to flag 'codes' to a broad categories of:

 

- all characters

- all numeric

- any alphanumeric

 

I find categorizing codes for more generic conditions harder than specific conditions met shown below.

 

Any help please?  What am I doing wrong? Thanks in advance.

 


data have;
input codes $; 
datalines;
0D7Q8ZZ
XHRPXL2
0090T99
0090THJ
123456788
23456
234
0090T
0987F
HYDHDJH
;
/*Help is appreciated to work below codes work out*/
data x; set have; if prxMatch("/^D+\s*$/o",codes) then flag = "all character"; if prxMatch("/^[a-z]+\s*$/o",codes) then flag = "all character"; if prxMatch("/^[a-z]*\s*$/o",codes) then flag = "all character";
if prxMatch("/^w*\s*$/o",codes) then flag = "any alphanumeric"; if prxMatch("/^d+\s*$/o",codes) then flag = "all_numeric"; run; proc freq data=x; tables flag; run;

/*codes worked fine*/

if prxMatch("/^\d{5}.{2}\s*$/o",codes) then flag="CPT1";
else if prxMatch("/^\d{4}F.{2}\s*$/o",codes) then flag = "CPT2";
else if prxMatch("/^\d{4}T.{2}\s*$/o",codes) then flag = "CPT3";

else if prxMatch("/^V\d+\s*$/o",codes) then flag="VCODE";
else if prxMatch("/^E\d+\s*$/o",codes) then flag="ECODE";
else if prxMatch("/^\d{1}\s*$/o",codes) or
        prxMatch("/^\d{2}\s*$/o",codes) or
        prxMatch("/^\d{3}\s*$/o",codes) or  
        prxMatch("/^\d{4}\s*$/o",codes) then flag = "ICD9";

 


Accepted Solutions
Solution
a week ago
PROC Star
Posts: 503

Re: prxmatch / all character, all numeric or any alphanumeric

something like below should work 

data have;
input codes $; 
datalines;
0D7Q8ZZ
XHRPXL2
0090T99
0090THJ
123456788
23456
234
0090T
0987F
HYDHDJH
;

data x; set have;
length flag $30.;
if prxMatch("/^[a-z]+$/i",trim(codes)) then flag = "all character"; 
 else if prxMatch("/^[0-9]+$/o",trim(codes)) then flag = "all numeric"; 
 else if prxMatch("/^[a-z0-9]+$/i",trim(codes)) then flag = "any alphanumeric"; 
run;

View solution in original post


All Replies
Solution
a week ago
PROC Star
Posts: 503

Re: prxmatch / all character, all numeric or any alphanumeric

something like below should work 

data have;
input codes $; 
datalines;
0D7Q8ZZ
XHRPXL2
0090T99
0090THJ
123456788
23456
234
0090T
0987F
HYDHDJH
;

data x; set have;
length flag $30.;
if prxMatch("/^[a-z]+$/i",trim(codes)) then flag = "all character"; 
 else if prxMatch("/^[0-9]+$/o",trim(codes)) then flag = "all numeric"; 
 else if prxMatch("/^[a-z0-9]+$/i",trim(codes)) then flag = "any alphanumeric"; 
run;
Super Contributor
Posts: 331

Re: prxmatch / all character, all numeric or any alphanumeric

Btw, why trim() function needed here? Just trying to get full grasp of what you're doing here. Thanks.
PROC Star
Posts: 503

Re: prxmatch / all character, all numeric or any alphanumeric

just to remove leading and trailing blanks

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 151 views
  • 2 likes
  • 2 in conversation