BookmarkSubscribeRSS Feed
PGStats
Opal | Level 21

After a bit of experimenting with the PRX - INFORMAT technique, starting with 's third example, I came to :

proc format;

invalue ReDollar (default=32767)

's#.*\$\s?(\d+(\.\d{2})?).*#\1#' (regexpe) = [12.];

run;

data want3;

set have;

price=input(pt, ReDollar.);

format price dollar8.2;

run;

I dropped the non-capturing group and the begin-end assertions from the pattern since they are not required. I changed the label informat dollar8.2 to 12. as it divided the price by 100. Most importantly, I specified a large default size for the informat; otherwise, longer input strings were truncated.

PG

PG
FriedEgg
SAS Employee

It is important to note that in the case where a variable this format would be applied to includes more that one valid dollar value, the last one will be returned.  This is true of all the examples: mine, ,

This is because of the use of the greedy match at the beginning (.*), if you alternatively wanted to retrieve the first match, you could modify this to be a lazy match (.*?)

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
  • 16 replies
  • 4378 views
  • 4 likes
  • 8 in conversation