Perl regular expression in SAS.
Does anyone knows how I could achieve this using perl regular expressions in SAS.
I have this SAS dataset.
DATA given;
input poolno $ name $;
datalines;
00581591 FN
MSR0581591 GN
0581591 FN
A581591A58591 GN
0581591A FN
0581591BB GN
05815910 FN
'0581591 GN
;
run;
I want to apply below rules using SAS regular expressions.
IF LENGTH(POOLNO) > 6 then do the following.
# to that alphabetical character and not including it. Example: 123456A -> 123456
This is the desired sas dataset:
0581591 FN
585191 GN
0581591 FN
A581591 GN
0581591 FN
0581591 GN
0581591 FN
0581591 GN
Thanks in advance for you kind response.
DATA given;
input ( poolno name ) (: $20.);
newpoolno=prxchange('s#([''\b]|MSR0)?(\w\d{4,5}[1-9])[0\w]{0,}\b#$2#',-1,prxchange('s#^00#0#',1,poolno));
datalines;
00581591 FN
MSR0581591 GN
0581591 FN
A581591A58591 GN
0581591A FN
0581591BB GN
05815910 FN
'0581591 GN
;
run;
An additional note, taken in priority, your rules and results do not mesh perfectly. I coded to match the results provided rather than then rules you listed.
poolno | name | newpoolno |
00581591 | FN | 0581591 |
MSR0581591 | GN | 581591 |
0581591 | FN | 0581591 |
A581591A58591 | GN | A581591 |
0581591A | FN | 0581591 |
0581591BB | GN | 0581591 |
05815910 | FN | 0581591 |
'0581591 | GN | 0581591 |
DATA given;
input ( poolno name ) (: $20.);
newpoolno=prxchange('s#([''\b]|MSR0)?(\w\d{4,5}[1-9])[0\w]{0,}\b#$2#',-1,prxchange('s#^00#0#',1,poolno));
datalines;
00581591 FN
MSR0581591 GN
0581591 FN
A581591A58591 GN
0581591A FN
0581591BB GN
05815910 FN
'0581591 GN
;
run;
An additional note, taken in priority, your rules and results do not mesh perfectly. I coded to match the results provided rather than then rules you listed.
poolno | name | newpoolno |
00581591 | FN | 0581591 |
MSR0581591 | GN | 581591 |
0581591 | FN | 0581591 |
A581591A58591 | GN | A581591 |
0581591A | FN | 0581591 |
0581591BB | GN | 0581591 |
05815910 | FN | 0581591 |
'0581591 | GN | 0581591 |
sorry ,I made a mistake when writing the desired sas data set but i have what i needed.
Thanks for your help.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.