Hello, This lies more along the realm of data management. I have a dataset where I want to flag observations for errors. The variables are a set of questions/responses and the responses are either Yes (1) or No (0). As you'll see in the example dataset below, variables Q4a1 to Q4a9 are a group of responses from 'Question4.' If a respondent answers 'Yes' to question 4, then at least one entry (Yes) must be made in variables Q4a1 to Q4a9. Example: Question4-Do you have a favorite food? (Yes-1/No-0) Check box Q4a1- Pizza (Response is either 1 or 0) Q4a2-Steak (1/0) Q4a4- Pasta (1/0) Q4a5- Other (1/0) .....etc. I want to be able to flag respondents where they answered yes to Question 4 but they made no selection for Q4a1 through Q4a9. I created an array but i'm running into difficulty where it seems to be flagging respondents (variable Data1-Data12) that didn't make a selection for the last response (Q4a9) instead of flagging 'Data2' and 'Data4' where no entries were made in Q4a1 - Q4a9. The frequency table should be: Q4a Freq 0 9 1 2 Where 2 respondents that made no selections in Q4a1-Q4a9 are flagged. But instead I'm getting this: Q4a Freq 0 4 1 7 Where it seems to be flagging non-responses for Q4a9. Have attached code below: data DataInput; input Data $ Question1:32. Question2:32. Question3:32. Question4:32. Q4a1:32. Q4a2:32. Q4a3:32. Q4a4:32. Q4a5:32. Q4a6:32. Q4a7:32. Q4a8:32. Q4a9:32.; datalines; DATA1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 DATA2 1 0 0 1 0 0 0 0 0 0 0 0 0 0 DATA3 1 1 0 1 1 1 1 0 1 0 1 1 0 0 DATA4 1 0 0 1 0 0 0 0 0 0 0 0 0 0 DATA5 1 1 0 1 0 1 0 1 1 1 1 0 1 1 DATA6 1 1 0 1 0 1 0 1 1 1 1 0 1 1 DATA7 1 1 0 1 0 1 0 1 1 1 1 0 1 1 DATA8 1 1 0 1 0 1 0 1 1 1 1 0 1 1 DATA9 1 1 0 1 0 0 0 0 0 0 0 1 0 0 DATA10 1 1 0 1 0 0 0 0 0 0 0 1 0 0 DATA11 1 1 0 1 0 1 0 1 1 1 1 1 0 0 DATA12 1 1 0 1 0 1 0 1 1 1 1 1 0 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; data datainput_array; set datainput; array Q4a_ARRAY (9) Q4a1 - Q4a9; do i= 1 to 9; if Question1=1 then do; if Question4=1 and (Q4a_ARRAY(i) = 0) then Q4a=1; else Q4a=0; end; end; run; proc freq data=datainput_array; TABLE Q4a; RUN; proc sort data=datainput_array out=Q4a_0; Where Q4a=0; by Data; run; proc sort data=datainput_array out=Q4a_1; Where Q4a=1; by Data; run;
... View more