4

In Access I'd take the column I'm looking to get the data from select it. Go to its properties, go to Top Values, and I'd put in the percentage I wanted of the current list. For instance a Cost list. 1000 members, I only want to know the top 2% of cost of my members. I place 2% in and the list shows the top 2% of cost of my members.

How can I do this in SAS?

Joe
  • 62,789
  • 6
  • 49
  • 67
Xodiak
  • 41
  • 1

2 Answers2

5

I'd just use proc rank.

groups=100 creates 100 ranked groups based on the variable var1 specified in the var statement. The ranks statement puts the groups into a new variable percentile.

proc rank data=have out=have_ranked groups=100;
  ranks percentile;
  var var1;
run;

data want;
  set have_ranked;
  where percentile ge 98;
run;
DWal
  • 2,752
  • 10
  • 19
  • The extra data step is unnecessary - you can use a where clause on the out= dataset specified in the proc rank statement. For people unfamiliar with the proc, it's also worth mentioning that the first group is 0 rather than 1. – user667489 May 05 '15 at 12:25
2

You could also use proc univariate to get cutoff point for top 2%, then select obs you need. Something like:

proc univariate data=sashelp.class;
    var weight;
    output out=cutoff pctlpts=98 pctlpre=weight;
 run;

data class;
   set sashelp.class;
   if _n_=1 then set cutoff;
   if weight>=weight98 then output;
run;
Shenglin Chen
  • 4,504
  • 11
  • 11