BookmarkSubscribeRSS Feed
SannaSanna
Quartz | Level 8

I have a dataset containing various different 'modes' They are labelled ELA_MOD1, ELAL_MOD2.. etc up through 9.  I am hoping to run a code that will go through each of the 9 'modes' to determine if "Y" was entered.   Is there a quick way to run this through SAS other than writing a separate if-then statement for each 'mode'?   Can anyone offer me some assistance?  Thank you

IDGRADEMODE1MODE2MODE3MODE4MODE5MODE6MODE7MODE8MODE9
AB987310YY
TR22911YY
SE950010
MR914812YY
FO231912Y
5 REPLIES 5
Reeza
Super User

If a Y is any of the fields? Can there be any other entries?

Assuming not there's several options.

num_non_missing=n(of mode1--mode9); (I never remember if its one or two dashes).

mode_found=whichc("Y", of mode1--mode9);

SannaSanna
Quartz | Level 8

Yes- the field can also contain "N" or blank.

Reeza
Super User

then use the whichc function to find if there is a Y, it will return a number, e.g 3 means mode3 was the one with a Y. 

Linlin
Lapis Lazuli | Level 10

Reeza,

One dash is fine.

Linlin
Lapis Lazuli | Level 10

try:

data have;

input (m1-m5)($);

cards;

n y n y n

Y n n n n

n n n n n

;

data want;

length is_a_y $3;

set have;

is_a_y=ifc(findc(cats(of m1-m5),'y','i'),'YES','NO');

proc print;run;

obs    is_a_y    m1    m2    m3    m4    m5

1      YES      n     y     n     y     n

2      YES      Y     n     n     n     n

3      NO       n     n     n     n     n

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1856 views
  • 6 likes
  • 3 in conversation