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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.