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 (.*?)

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 6745 views
  • 4 likes
  • 8 in conversation