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?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.