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

Hi Team,

 

I have a dataset ABC

Var 1                                                 Var2                                                        Var3

PPO with HRA LocalPlus®              Silver                                                         PTO Cash Out

 

I need to set an Indicator Y  if any if the variable 1, 2 or 3 contains LIKE'%Local%' .

 

IF Var1 or Var2 or var3 LIKE'%Local%' . THEN Var4 = 'Y';

 

Please help as how we can do this, as LIKE works with were , what other option we have to do this and get expected result.

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Array.

data a;
input (Var1-Var3) (& $40.);
cards;
PPO with HRA LocalPlus       Silver               PTO Cash Out
PPO with HRA LPlus       Silver               PTO Cash Out
;
data want; 
 set a;
 array x{*} $ var: ;
 do i=1 to dim(x);
  if find(x{i},'Local') then do; flag='Y';leave;end;
 end;
 drop i;
run;

View solution in original post

2 REPLIES 2
Ksharp
Super User

Array.

data a;
input (Var1-Var3) (& $40.);
cards;
PPO with HRA LocalPlus       Silver               PTO Cash Out
PPO with HRA LPlus       Silver               PTO Cash Out
;
data want; 
 set a;
 array x{*} $ var: ;
 do i=1 to dim(x);
  if find(x{i},'Local') then do; flag='Y';leave;end;
 end;
 drop i;
run;
Tom
Super User Tom
Super User

You cannot use LIKE with IF.  That only works with WHERE statements.

But since all you are doing is looking for a substring you can just use one of the many functions that do that.  INDEX(), FIND(), INDEXW(), FINDW().

Since you don't care which variable you find it you can just combine all of them and search that.

IF index(cats(of var1-var3),'Local') THEN Var4 = 'Y';

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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