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

Hi all,

 

My data set has a column that can have any alphanumeric characters or special symbols, but I want to flag only those records that have a certain type of alphanumeric string in them. For eg, values in my string could be :

 

JT 5366792.2 849M2 PP???   (to be picked up)

JT 1.501 HA   (don't pick up coz there is no 7-8 digit string before the dot)

JT 5394885.2 852M2 GV (pick up)

JT B749106.3 685M2 RV 09/99  (pick up)

 

the records that I want to pick are the ones that have the registration numbers in format : B749106.3 or 5366792.2. Usually there will be a . present with only one digit after it but the string before . could contain either characters or numbers (length of the total string could be 7-8 characters before the dot(.). Is there any way I can code around this. 

 

I don't need to output the exact registration number, but only need to highlight the row that contains that registration number in that format. 

 

Any help with SAS code is much appreciated.

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
russt_sas
SAS Employee

Here is one way to accomplish this, you can use PRXPARSE to create the pattern and then PRXMATCH to match the pattern, for example:

 

data one;
input val $27.;
cards;
JT 5366792.2 849M2 PP???
JT 1.501 HA
JT 5394885.2 852M2 GV
JT B749106.3 685M2 RV 09/99
;

data new;
set one;
if _n_=1 then do;
pattern1=prxparse('/\d\d\d\d\d\d\d.\d/');
pattern2=prxparse('/\w\d\d\d\d\d\d.\d/');
end;
retain pattern1 pattern2;
pos1=prxmatch(pattern1,val);
pos2=prxmatch(pattern2,val);
run;

proc print;
run;

View solution in original post

1 REPLY 1
russt_sas
SAS Employee

Here is one way to accomplish this, you can use PRXPARSE to create the pattern and then PRXMATCH to match the pattern, for example:

 

data one;
input val $27.;
cards;
JT 5366792.2 849M2 PP???
JT 1.501 HA
JT 5394885.2 852M2 GV
JT B749106.3 685M2 RV 09/99
;

data new;
set one;
if _n_=1 then do;
pattern1=prxparse('/\d\d\d\d\d\d\d.\d/');
pattern2=prxparse('/\w\d\d\d\d\d\d.\d/');
end;
retain pattern1 pattern2;
pos1=prxmatch(pattern1,val);
pos2=prxmatch(pattern2,val);
run;

proc print;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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