BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

@hernan_AR wrote:

this is the regex

 

s/(^.*)(SomeAlphaNumPrefix)([\d]+)(\.sas7bdat)$/$3/

 

with this, I get the digits between the prefix and the extension to the end

because I just need the digits, discarding the rest

 

do you see anything wrong here ?

 


Yes. The pattern is NOT accounting for the trailing spaces that will be padded onto a fixed length variable so that its length matches the defined length of the variable.  You could for example do something like:

s/(^.*)(SomeAlphaNumPrefix)([\d]+)(\.sas7bdat\ *)$/$3/

 

ChrisNZ
Tourmaline | Level 20
$ means end of string. If you don't trim you have spaces at the end as I said, so you can't match this expression.
Tom
Super User Tom
Super User

Note if you want the last word in a line use the SCAN() function with -1 as the index.  Much easier (and faster) then REGEX.

extension = scan(row,-1,'.');
hernan_AR
SAS Employee

oh, good to know it

that's why communities llike this are great!

thanks

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!

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.

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
  • 18 replies
  • 2259 views
  • 4 likes
  • 3 in conversation