- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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';