02-12-2014 04:11 PM
I have data that looks like this:
A1 A2 A3 A4
1 1 2 3
2 4 5 1
4 5 2 3
4 2 3 2
5 5 4 5
1 2 3 4
I would like a variable corresponding to each previous variable to indicate whether or not it is a 4 or a 5.
And I would like this for each variable. Right now I have an array set up, but for some reason it is not doing what I thought it would. Any help is greatly appreciated.
array a_questions (18) a1-a18;
array a_positive (18) p1-p18;
do i = 1 to 18;
if a_questions = 4 or a_questions = 5 then a_positive = 1;
else a_positive = 0;
02-12-2014 05:30 PM
You might tell us in what way it isn't behaving as expected. I might guess that if any of your A variables are missing a value that you do not want the P value assigned. If that is the case then you want to only do the assignment when the variable isn't missing.
The IN operator is easer to read and update for enumerated values either numeric or string so you don't have to write a bunch of comparisons in your if statement.
BTW, An equivalent code for the assignment you are currently using would be:
a_positive = (a_questions in (4,5));
If not missing(a_questions) then a_positive = (a_questions in (4,5));