Help using Base SAS procedures

prxmatch

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

prxmatch

Hi All,

I have thousands of different string in variable "var". I want to pick only those records having (/ or missing)

data have;

input grp $40.     var $20.;

cards;

AAAAA               Par_diff

BBBB                 rag*diff

CCCC                rAg/diff

DDDD             

EEEEE              run_diF

;

run;

want: records with var (/,missing)

output:

CCCC        rag/diff

DDDD     

i am using

prxmatch("m/ragdiff/io",compress(var,'/'))>0 & Missing(var)

Thanks

Sam


Accepted Solutions
Solution
‎02-28-2015 12:20 AM
Trusted Advisor
Posts: 1,300

Re: prxmatch

You can accomplish the same thing without the strip by looking for a string containing only spaces.

where prxmatch('#/|^\s+$#o', var);

View solution in original post


All Replies
Trusted Advisor
Posts: 1,300

Re: prxmatch

You main issue is having 'and' where it should be 'or.'  I would not recommend using the regular expression, given your example (which I would also rewrite as prxmatch('#/|^\s+$#o', var) given your explained requirements).

where index(var, '/') or missing(var);

Regular Contributor
Posts: 168

Re: prxmatch

Thank you FriedEgg, i am under learning curve. i would like to achieve that using regular expression

Thanks

Sam

Trusted Advisor
Posts: 1,300

Re: prxmatch

A good thing to learn would be that this is an inefficient use-case for regular expression.

Respected Advisor
Posts: 3,124

Re: prxmatch

Well, this seems working for me , it came to me as a surprise:

data have;

     input grp :$40.     var :$20.;

     cards;

AAAAA               Par_diff

BBBB                 rag*diff

CCCC                rAg/diff

DDDD             .

EEEEE              run_diF

;

run;

data want;

     set have;

     if prxmatch('/\/|^$/', strip(var))>0;

run;

Solution
‎02-28-2015 12:20 AM
Trusted Advisor
Posts: 1,300

Re: prxmatch

You can accomplish the same thing without the strip by looking for a string containing only spaces.

where prxmatch('#/|^\s+$#o', var);

Regular Contributor
Posts: 168

Re: prxmatch

Thanks to both!!! Work like champ!!!!

COuld you please explain what special character matches (/) & space?  From the variable var....In the above regular expression

Thanks

sam

Trusted Advisor
Posts: 1,300

Re: prxmatch

\/|^\s+$

Match either the regular expression below (attempting the next alternative only if this one fails) «\/»

   Match the character “/” literally «\/»

Or match regular expression number 2 below (the entire match attempt fails if this one fails to match) «^\s+$»

   Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»

   Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s+»

      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»

   Assert position at the end of a line (at the end of the string or before a line break character) «$»

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 415 views
  • 7 likes
  • 3 in conversation