lundi 27 juillet 2015

SAS: assigning variables based on another variable

I am trying to learn SAS. I see the following code in one of the programs:

data _null_;
    set Rates;
    IF attained_age = '<60'   then call symput('U_60_Alpha',count);
    IF attained_age = '<60'   then call symput('U_60_Beta',exposure);
    IF attained_age = '60-64' then call symput('U_60_64_Alpha',count);
    IF attained_age = '60-64' then call symput('U_60_64_Beta',exposure);
    IF attained_age = '65-69' then call symput('U_65_69_Alpha',count);
    IF attained_age = '65-69' then call symput('U_65_69_Beta',exposure);
run;

Would a better way to write this be something like this?

data _null_;
    set Rates;
    select (attained_age);
        when('<60');
          do;
             symput('U_60_Alpha',count);
             symput('U_60_Beta',exposure);
          end;
        when('60-64');
          do;
             symput('U_60_64_Alpha',count);
             symput('U_60_64_Beta',exposure);
          end;
        when('65-69');
          do;
             symput('U_65_69_Alpha',count);
             symput('U_65_69_Beta',exposure);
          end;
    end;
run;

Not sure if this is better or worse than the previous block - certainly takes more vertical space, but likely runs faster (much less comparisons needed). Are there other pros/cons? Which one would be preferable from your point of view?

Aucun commentaire:

Enregistrer un commentaire