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';

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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