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!
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;
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;
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!
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.