DATA Step, Macro, Functions and more

Condense IF FIND

Reply
anonymous_user
Posts: 0

Condense IF FIND

[ Edited ]

Hi, how do I create an INLIST pn an IF FIND?



Super User
Super User
Posts: 7,942

Re: Condense IF FIND

Posted in reply to anonymous_user

What does posting_cat_2 look like.  Post your test data in the form of a datastep so that we can see what you see and assess the best way to achieve this.  If that variable just contains a, b, or c then:

select(posting_cat_2);

  when ('a') ...

...

 

If it contains more, then what happens if more than one appear in the string?  Is there a defining pattern which can identify these uniquely?

 

You may find it simpler to do a quick loop:

do i=1 to lengthn(posting_cat_2);
  if char(posting_cat_2,i) in ('a','b',...) then perf='3) >=...';
end;
anonymous_user
Posts: 0

Re: Condense IF FIND

[ Edited ]
 
Super User
Super User
Posts: 7,942

Re: Condense IF FIND

Posted in reply to anonymous_user

Then the simplest way is:

if char(posting_cat_2,1) in ("a","b"...) then ...;

 

Super User
Posts: 7,760

Re: Condense IF FIND


RW9 wrote:

Then the simplest way is:

if char(posting_cat_2,1) in ("a","b"...) then ...;

 


or

if scan(posting_cat,1,'.') in ('a','b',...) then ...;

just for adding another option Smiley Wink

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 233

Re: Condense IF FIND

Posted in reply to anonymous_user

Hello,

 

if prxmatch('/[a-j]\./',posting_cat2_new) then ...

Respected Advisor
Posts: 3,156

Re: Condense IF FIND


gamotte wrote:

Hello,

 

if prxmatch('/[a-j]\./',posting_cat2_new) then ...


I like it. I would just tweak a little to make it more robust,

 

if prxmatch('/^[a-j]\./',left(posting_cat2_new)) then ...

 

Super User
Posts: 5,497

Re: Condense IF FIND

Posted in reply to anonymous_user

If your sample values are all left-hand justified, you can also use:

 

if posting_cat2_new in : ('a.', 'b.', 'c.', 'd.', 'g.', 'h.', 'k.', 'i.', 'j.') then ...

Ask a Question
Discussion stats
  • 7 replies
  • 406 views
  • 1 like
  • 6 in conversation