BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Linus69
Calcite | Level 5

Hi!

 

We've just got access to SAS as a tool, and now I'm trying to translate my previous scripts from SQL. 

I'm having trouble finding a commando like "rlike" - if anyone could please help me?
I've tried to make an example her of what I'm trying to do:

 

PROC SQL;
Create table test as
Select CreatedDate, DiscountCode, MemberId, ChangedFields
from my.source
where ChangedFIelds rlike 'discountCode:[0-9][0-9][0-9][0-9][0-9]->null'
ORDER BY CreatedDate;

 

So.. How to do this in SAS EG?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

I wasn't sure about the whitespace situation between 'discountCode:' and the digits, so this might work:

 

data have;
input changedfields $80.;
datalines;
discountCode:12345->null
discountCode:67890->null
discountCode: 87654->null
discountCode:1x345->null
something else
;

proc sql;
 create table want as select changedfields from have
  where prxmatch('/discountCode:(\s*(\d\d\d\d\d))->null/',changedfields)>0;
quit;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

SAS does not provide such an operator (which looks like a LIKE with regular expressions to me).

The straightforward thing to do (IMO) is using basic comparisons with substrings and testing for numeric data:

data have;
input changedfields $80.;
datalines;
discountCode:12345->null
discountCode:67890->null
discountCode:1x345->null
something else
;

data want;
set have;
where
  index(ChangedFIelds,'discountCode:') = 1 and
  notdigit(substr(ChangedFIelds,14,5)) = 0 and
  substr(ChangedFIelds,19,6) = '->null'
;
run;

Someone who is an expert on SAS perl regular expressions may come up with a more elegant solution.

ChrisHemedinger
Community Manager

I wasn't sure about the whitespace situation between 'discountCode:' and the digits, so this might work:

 

data have;
input changedfields $80.;
datalines;
discountCode:12345->null
discountCode:67890->null
discountCode: 87654->null
discountCode:1x345->null
something else
;

proc sql;
 create table want as select changedfields from have
  where prxmatch('/discountCode:(\s*(\d\d\d\d\d))->null/',changedfields)>0;
quit;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Linus69
Calcite | Level 5

Thank you! That really sent me into the right direction Smiley Happy

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1237 views
  • 3 likes
  • 3 in conversation