Friday, January 11, 2013

SAS: PROC CONTENTS list variables in order created

I have often been annoyed that SAS' PROC CONTENTS lists variables in alphabetical order rather than the order in which they appear in the dataset.  Turns out there is an option, varnum, which causes the variables to be listed in my preferred order.  Here's some sample code:

    * Demo varnum option on PROC CONTENTS ;
    data work.kids;
    input name $ age gender $;
    datalines;
    Kamina 6 F
    Raelani 4 F
    Elliott 1 M
    ;
    run;

    proc contents data=work.kids;
    run;

    proc contents data=work.kids varnum;
    run;


And some (truncated) output...

    Alphabetic List of Variables and Attributes

           #    Variable    Type    Len

           2    age         Num       8
           3    gender      Char      8
           1    name        Char      8



            Variables in Creation Order

           #    Variable    Type    Len

           1    name        Char      8
           2    age         Num       8
           3    gender      Char      8



No comments:

Post a Comment