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!
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;
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;
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';
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.