New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
daradanye
Obsidian | Level 7

Hi,

 

I need to use SAS regular expression to extract a substring from some messy strings.  I've compiled regular expression patterns but not quite sure how to do that in SAS.

 

The examples are as follows:

 

HaveWant
a2191625zex-10_14.htm10_14
ade4378dexhibit10_2.txt10_2

 

The regular expression I come up with is (ex\D*)(\d+\D+\d*)

 

I am using two sets of brackets here to group.  In Python or other languages, I can locate what I want by identify group(2).  Is there any similar function here in SAS?

 

I would be very grateful if someone can help out here.

 

Thanks,

Dara

3 REPLIES 3
PGStats
Opal | Level 21

Try prxChange:

 

want = prxChange("/.*ex\D*(\d+\D\d*).*/\1/", 1, have);
PG
Ksharp
Super User
data x;
input have : $40. ;
pid=prxparse('/[\d_]+(?=\.[a-z]+)/io');
if pid>0 then do;
call prxsubstr(pid,have,p,l);
want=substr(have,p,l);
end;
cards;
a2191625zex-10_14.htm
ade4378dexhibit10_2.txt
;
proc print;run;
Ksharp
Super User

OR this Scan():

 

data x;
input have : $40. ;
want=scan(scan(have,1,'.'),-1,'_','kd');
cards;
a2191625zex-10_14.htm
ade4378dexhibit10_2.txt
;
proc print;run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1503 views
  • 0 likes
  • 3 in conversation