Hello!
i have a database that looks like this:
idnum text1 text2 text3 text4 text5 text6 text7.....text35
1 bsf ttg Hht Hht Hhp. Ppj Ggt Tty
2 Yyy. Hjs. Hht Tty Hgy. Xyz. Yyu. Kio
.
.
what i want to do is this, but in a practical way:
if text1 in (‘Hht’, ‘Tty’, ‘kyo’) or text2 in (‘Hht’, ‘Tty’, ‘kyo’) or text3 in (‘Hht’, ‘Tty’, ‘kyo’) ......or text35 in (‘Hht’, ‘Tty’, ‘kyo’) then new_var=1;
else new_var=0;
any tips?
data want;
set have;
array j text:;
do t='Hht', 'Tty', 'kyo';
new_var= t in j ;
if new_var then leave;
end;
drop t;
run;
data want;
set have;
array j text:;
do t='Hht', 'Tty', 'kyo';
new_var= t in j ;
if new_var then leave;
end;
drop t;
run;
There are many ways to skin a cat. The shortest code is probably this:
data want;
set have;
new_var=whichc('Hht',of text1-text35) or whichc('Tty',of text1-text35) or whichc('kyo',of text1-text35);
run;
Thank you!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.