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.

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