Help using Base SAS procedures

Simplify searching codes?

Accepted Solution Solved
Reply
Super Contributor
Posts: 398
Accepted Solution

Simplify searching codes?

Hello:

 

Could someone help me to simply the codes below? Maybe macro or array? or something else?  Thanks.

 

 

data want;

set have;

Labelpos1=find(label," NOS","i");

Labelpos2=find(label,"NOS ","i");

Labelpos3=find(label,"-NOS","i");

Labelpos4=find(label,"NOS-","i");

Labelpos5=find(label,"MISC","i");

Componentpos1=find(Component," NOS","i");

Componentpos2=find(Component,"NOS ","i");

Componentpos3=find(Component,"-NOS","i");

Componentpos4=find(Component,"NOS-","i");

Componentpos5=find(Component,"MISC","i");

Productpos1=find(Product," NOS","i");

Productpos2=find(Product,"NOS ","i");

Productpos3=find(Product,"-NOS","i");

Productpos4=find(Product,"NOS-","i");

Productpos5=find(Product,"MISC","i");

run;

 

data nos;

set want;

where Labelpos1 ne 0 or Labelpos2 ne 0 or Labelpos3 ne 0 or Labelpos4 ne 0 or Labelpos5 ne 0

or Componentpos1 ne 0 or Componentpos2 ne 0 or Componentpos3 ne 0 or Componentpos4 ne 0 or Componentpos5 ne 0

or Productpos1 ne 0 or Productpos2 ne 0 or Productpos3 ne 0 or Productpos4 ne 0 or Productpos5 ne 0;

run;


Accepted Solutions
Solution
‎12-08-2017 11:45 AM
PROC Star
Posts: 8,164

Re: Simplify searching codes?

Or, if you don't need to keep each find location:

 

data have;
  informat label component product $4.;
  input label component product;
  cards;
this that none
this nos some
the same -nos
not not not
not not misc
;

data want;
  set have (where=(max(
      prxmatch('/NOS| NOS|-NOS|NOS-|MISC/i',label),
      prxmatch('/NOS| NOS|-NOS|NOS-|MISC/i',Component),
      prxmatch('/NOS| NOS|-NOS|NOS-|MISC/i',Product) ) gt 0));
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Super User
Posts: 10,784

Re: Simplify searching codes?

data _null_;
x='Could someone help me NOS';
if prxmatch('/NOS| NOS|-NOS|NOS-/i',x) then putlog 'Found';
run;
Solution
‎12-08-2017 11:45 AM
PROC Star
Posts: 8,164

Re: Simplify searching codes?

Or, if you don't need to keep each find location:

 

data have;
  informat label component product $4.;
  input label component product;
  cards;
this that none
this nos some
the same -nos
not not not
not not misc
;

data want;
  set have (where=(max(
      prxmatch('/NOS| NOS|-NOS|NOS-|MISC/i',label),
      prxmatch('/NOS| NOS|-NOS|NOS-|MISC/i',Component),
      prxmatch('/NOS| NOS|-NOS|NOS-|MISC/i',Product) ) gt 0));
run;

Art, CEO, AnalystFinder.com

 

Super Contributor
Posts: 398

Re: Simplify searching codes?

Hi Art297:

 

Your codes are wonderful.   But what is MAX used for?

PROC Star
Posts: 8,164

Re: Simplify searching codes?

I used max instead of OR. That is, if the largest resulting value from either of the three calls is greater than zero.

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 13,561

Re: Simplify searching codes?

Example input is where?

Desired output is what?

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 222 views
  • 3 likes
  • 4 in conversation