DATA Step, Macro, Functions and more

susbstrn statement with different lengths variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 136
Accepted Solution

susbstrn statement with different lengths variables

Hi all,

I have the following statement:

 

data a (drop=i); set b; array x{*} dx:; r=1=0;

do i=1 to dim(x); if susbtrn(x{i},1,3) in ('210','220') then do; r=1;

leave;

end;

end;

run;

 

my question if I want to include another entry with a length of 4 meaning if susbtrn= '210', '220', '2320', how can I adjust the above statement to account for different the lengths?

 


Accepted Solutions
Solution
‎05-06-2018 03:47 PM
PROC Star
Posts: 1,803

Re: susbstrn statement with different lengths variables

Posted in reply to lillymaginta

data a (drop=i); set b; array x{*} dx:; r=1=0;

do i=1 to dim(x);
if susbtrn(x{i},1,3) in ('210','220')
or susbtrn(x{i},1,4) in ( '2320')
then do; r=1;

leave;

end;

end;

run

View solution in original post


All Replies
Solution
‎05-06-2018 03:47 PM
PROC Star
Posts: 1,803

Re: susbstrn statement with different lengths variables

Posted in reply to lillymaginta

data a (drop=i); set b; array x{*} dx:; r=1=0;

do i=1 to dim(x);
if susbtrn(x{i},1,3) in ('210','220')
or susbtrn(x{i},1,4) in ( '2320')
then do; r=1;

leave;

end;

end;

run

Super User
Posts: 6,772

Re: susbstrn statement with different lengths variables

Posted in reply to lillymaginta

I'm not sure you have the spelling right, but here's a variation that works for character strings:

 

if x{i} in : ('210','220','2299') then do;

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 156 views
  • 1 like
  • 3 in conversation