Hi,
Im working on an survey analysis and found SAS code that creates what I want to do but I do not have SAS. Can anyone help me translate this code to R
LABEL SUSCEP = 'Susceptibility Index';
if &CR7SUSCEP.=1 then do;
if &CR12SUSCEP. IN (2,3,4,5,6,7) then SUSCEP=3; *experimenter;
if &CR12SUSCEP.=8 then SUSCEP=4; *established;
end;
ELSE if &CR7SUSCEP.=2 then do;
if &CR8SUSCEP.=4 and &CR9SUSCEP=3 and &CR10SUSCEP=4 then SUSCEP=1;
*nonsusceptible, never smokers;
else SUSCEP=2; *susceptible never smoker;
if &CR8SUSCEP.=. And &CR9SUSCEP.=. And &CR10SUSCEP.=. Then SUSCEP=.;
end;
What I have tried:
yts_ms <- mutate(yts_ms, suscep = as.factor(ifelse(&CR7SUSCEP == 1, ifelse(&CR12SUSCEP %in% 2:7, 3, ifelse(&CR12SUSCEP == 8, 4)))))
This is as far as I could get and I'm not sure if this is right. I could not figure out how to translate the else if &CR7SUSCEP.==2 part of the code.