Search code examples
sas

How to create decils in SAS inside a grouped variable


I want create decils in each level of a grouped variable in SAS.

For example, if I had the students' marks by subject, I would like to create calculate decils for each subject. Filtering the database for each subject, calculating the deciles and then merging them is not a solution since the problem I am dealing with has more than 80 levels in the grouped variable.


Solution

  • Use proc rank with a BY variable.

    proc rank data=have out=want ranks=10;
    by subject;
    var marks;
    ranks mark_rank;
    run;