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;
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
data _null_;
x='Could someone help me NOS';
if prxmatch('/NOS| NOS|-NOS|NOS-/i',x) then putlog 'Found';
run;
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
Hi Art297:
Your codes are wonderful. But what is MAX used for?
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
Example input is where?
Desired output is what?
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: