BookmarkSubscribeRSS Feed
surajmetha55
Fluorite | Level 6

I am trying following code:

data new;
 	input id Value $;
datalines;
1 50
2 1
3 500
4 56
5 1000
;
run;

data new1;
 	set new;
 		where prxmatch('/\d{2}/',Value);
run;
After submitting above code, I am getting following output:
ss.png

According to following documentation
https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/265-29.pdf

Expected output:

id Value
1 50
4 56

But in output I am getting 2 digit number and greater then 2 digit number even-though
my pattern is only for 2 digit number

 

 

 

4 REPLIES 4
PGStats
Opal | Level 21

Your pattern matches any string that includes at least two consecutive digits. Try this instead:

 

/^\d{2}\s*$/

 

 

PG
surajmetha55
Fluorite | Level 6

Tried with following changes but getting same output as shown in above screen shot. (two consecutive digits and greater then two consecutive digits )

where prxmatch('/\d{2}\s*$/',Value);

 

andreas_lds
Jade | Level 19

Interesting, i get the expected results:

36         data new1;
37            set new;
38            where prxmatch('/^\d{2}\s*$/', Value);
39            put _all_;
40         run;

id=1 Value=50 _ERROR_=0 _N_=1
id=4 Value=56 _ERROR_=0 _N_=2
NOTE: There were 2 observations read from the data set WORK.NEW.
      WHERE PRXMATCH('/^\d{2}\s*$/', Value);
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @surajmetha55 

 

The devil is in the detail. You omitted the little caret-symbol ^ from @andreas_lds 's code.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 1245 views
  • 4 likes
  • 4 in conversation