BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
K_S
Quartz | Level 8 K_S
Quartz | Level 8

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;
s_lassen
Meteorite | Level 14

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1048 views
  • 2 likes
  • 3 in conversation