mercredi 22 avril 2015

SAS create 10 new variables according to 10 existing one with a do loop

I have a PAR file, with 10 variables: q1-q10 which has values in range of 0-1. I need to create for each variable (q1,q2,q3...) a new variable that will receive values of 1-5 according to the following range 0< q <0.2 => 1

0.2< q < 0.4 => 2 and so on..

eventually for each q should be a new column should be an additional column with values from 1-5

I have managed to create it for one variable, but how can I do it for all 10 of them in a more efficient way?

 data PAR1; set PAR;
if q1>0 and q1<0.2 then do; qq1=1;end;
if q1>0.2 and q1<0.4 then do; qq1 =2;end;
if q1>0.4 and q1<0.6 then do; qq1=3;end;
if q1>0.6 and q1<0.8 then do; qq1=4;end;
if q1>0.8 and q1<1 then do; qq1=5;end;
run;
proc print data=PAR1;
run;

Aucun commentaire:

Enregistrer un commentaire