BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

5 REPLIES 5
Ksharp
Super User
data _null_;
x='Could someone help me NOS';
if prxmatch('/NOS| NOS|-NOS|NOS-/i',x) then putlog 'Found';
run;
art297
Opal | Level 21

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

 

ybz12003
Rhodochrosite | Level 12

Hi Art297:

 

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

art297
Opal | Level 21

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

 

ballardw
Super User

Example input is where?

Desired output is what?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1100 views
  • 3 likes
  • 4 in conversation