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
ID | GRADE | MODE1 | MODE2 | MODE3 | MODE4 | MODE5 | MODE6 | MODE7 | MODE8 | MODE9 |
AB9873 | 10 | Y | Y | |||||||
TR229 | 11 | Y | Y | |||||||
SE9500 | 10 | |||||||||
MR9148 | 12 | Y | Y | |||||||
FO2319 | 12 | Y |
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);
Yes- the field can also contain "N" or blank.
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.
Reeza,
One dash is fine.
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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.