Hello programmers, I have my variables like this: heart1, heart2, heart3, and each of these variables have responses coded as 1(most of the time), 2 (some of the time), 3 (rarely or never) I want to create 3 new dichotomous (0,1) variables named heartvar1-heartvar3 which corresponds to heart1-heart3 such that heartvar1=1 if heart1=1 and heartvar1=0 otherwise, if heart1 is not missing. I want to also do this for heart2 and heart3. I know i can use an array and a do over statement. Code is shown below data one; set have;
array heart1-heart3;
array heartvar1-heartvar3;
do over ya heart1-heart3;
if heart1=1 and heart1 ne . then heartvar1=1;
else heartvar1=0;
if heart2= 1 and heart2 ne . then heartvar2= 1;
else heartvar2=0;
if heart3 = 1 and heart3 ne . then heartvar3= 1;
else heartvar3=0;
end;
end;
end; My code did not run well and i was wondering what could be wrong. Thanks
... View more