Xodiak
Xodiak

Reputation: 41

Values in a column that are in a %

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?

Upvotes: 4

Views: 114

Answers (2)

Shenglin Chen
Shenglin Chen

Reputation: 4554

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;

Upvotes: 2

DWal
DWal

Reputation: 2762

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;

Upvotes: 5

Related Questions