I want to categorize some variables only if all of the variables in the array meet all the criteria. Any help on this would be greatly appreciated:
array ques{20} question1-question20;
do i=1 to 20;
if ques{i} ne . and ques{i}=4** then questcat=3;
end;
**only I want questcat=3 only if all of the nonmissing data in the array=4.
Thanks!
I'm not sure exactly what your rules are, seeing an example may help.
Guessing that if all questions values are 4 and none are missing then you could use the following logic:
max(of question1-question20)=min(of question1-question20) and nmiss(of question1-question20)=0 then ...
if your variables are character then you can try the cmiss function instead.
HTH,
Reeza
I'm not sure if I understand what you want to do. It sound like:
data have;
input question1-question20;
cards;
1 2 3 4 . 4 . 3 2 1 1 2 3 4 . 4 . 3 2 1
;
data want;
set have;
array ques{*} question1-question20;
do i=1 to dim(ques);
ques=ifn(ques eq 4,3,.);
end;
run;
Hi ... you don't have to use an ARRAY. Here's another idea (with only five questions, but it'll work with 20) ...
data test;
input q1-q5;
datalines;
4 4 4 4 4
. 2 3 1 4
4 . . . 4
. . . . .
1 2 3 4 5
. 4 4 4 .
;
run;
data test;
set test;
questcat = ifn(verify(catt(of q:),'.4') or sum(of q:) eq . , 9 , 3);
run;
proc print data=test noobs;
run;
q1 q2 q3 q4 q5 questcat
4 4 4 4 4 3
. 2 3 1 4 9
4 . . . 4 3
. . . . . 9
1 2 3 4 5 9
. 4 4 4 . 3
More info at ...
"Searching for Variable Values with CAT Functions: An Alternative to Arrays and Loops"
http://www.nesug.org/Proceedings/nesug09/ff/ff04.pdf
Great this is exactly what I need to do.
Thank you!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.