## how to use IF-Then

Regular Contributor
Posts: 161

# how to use IF-Then

Hello,

I have a dataset that I'd like to recode as followings:

recode the variables with the smallest value of 0.000623175 to polytomous items with 4 scores (0,1,2,3)

recode the variables with the smallest value of 0.001041523 to polytomous items with 3 scores (0,1,2)

and recode the variables with the smallest value o f0.002864969 to polytomous items with dichotomous.

Thank you

My code doesn't work:

data coded (drop=score1-score116 i);

set itemsc;

array score (116) score1-score116;

array f_item(116);

array t_item(116);

array d_item(116);

do i=1 to 116;

if score{i} lt 0.000623175 then DO;

if score{i} lt 0.000623175 then f_item{i}=3;

else if score{i} lt 0.002864969 then f_item{i}=2;

else if score{i} lt 0.013617708 then f_item{i}=1;

else if score{i} le 0.431834293 then f_item{i}=0;

if score{i} lt 0.001041523 then do;

if score{i} lt 0.001041523 then t_item{i}=2;

else if score{i} lt 0.008116862 then t_item{i}=1;

else if score{i} le 0.431834293 then t_item{i}=0;

else do;

if score{i} lt 0.002864969 then d_item{i}=1;

else if score{i} le 0.431834293 then d_item{i}=0;

end;

end;

end;

end;

run;

Super User
Posts: 23,700

## Re: how to use IF-Then

1) Look at where you end statements are.

2) Take a look at the condition that makes you enter the loop, first do

and then the lines after that. Those conditions will never be true.

I suggest getting the code working for one variable then moving on to implementing with an array.

Discussion stats