Help using Base SAS procedures

How to get a summary for the top 5%, 10% and other data

Reply
Frequent Contributor
Posts: 131

How to get a summary for the top 5%, 10% and other data

I have a sample with one dependent dummary variable y (0, 1). The data has been sorted.

Now the question is how I can get easily get a summary (e.g. mean, freq) for the top 5%, 10%, 15%, 20%, 25%, ... 95% sample. I hope there is a way to do this easily, rather than use separate steps to produce the results. Any procedure to do this, PROC UNIVARIATE, PROC FREQ, PROC MEANS? 

PROC Star
Posts: 7,361

How to get a summary for the top 5%, 10% and other data

You have to tell us more.  If you really do only have one dv, and it IS binary, I would think that just proc freq would provide everything that you need.  If it is more complex, proc rank might be what you are looking for.

Respected Advisor
Posts: 3,777

How to get a summary for the top 5%, 10% and other data

If the variable only has 2 levels it cannot be divided into 20 groups.

If you have a continuous variable then PROC RANK will divide the data into 20 groups and you can summarize using the GROUP as a class variable..

proc rank data=sashelp.heart out=g groups=20;

   var weight;

   ranks g;

   run;

proc means data=g;

   class g;

   var weight;

   run;

Frequent Contributor
Posts: 131

How to get a summary for the top 5%, 10% and other data

Sorry that I did not explain clearly.

What I want is to get the descriptive statistics for the top 5% data, top10% data, top 15%... Here, the data have been sorted in a proper order. The descriptive statistics are just for a single variable (which is a dummy type y=0 or 1).

Respected Advisor
Posts: 3,777

How to get a summary for the top 5%, 10% and other data

Just create a grouping variable based on obs number and total obs that makes 20 groups.

PROC Star
Posts: 7,361

How to get a summary for the top 5%, 10% and other data

and you may want to look into insight.  If you license it, you can activate it by either runing the word insight from the command line, or running the command DM "insight";

I have found it to be an invaluable way to see both the statistics, and graphical representations, of one's data.

Frequent Contributor
Posts: 131

Re: How to get a summary for the top 5%, 10% and other data

Thanks art297. I learned Smiley Happy

Super User
Posts: 9,676

Re: How to get a summary for the top 5%, 10% and other data

data test;
 do index=1 to 100;
  y=int(ranuni(-1)*2);
  output;
 end;
run;
proc sort data=test ;
 by descending index;
run;

%let dsid=%sysfunc(open(test));
%let nobs=%sysfunc(attrn(&dsid,nobs));
%let dsid=%sysfunc(close(&dsid));

%let want_percent=.2;
%let want_top=%sysevalf(&nobs*&want_percent,integer);
%put _user_;

proc means data=test(obs=&want_top) nway noprint;
 var y;
 output out=want mean= sum=/autoname;
run;

Ksharp

Ask a Question
Discussion stats
  • 7 replies
  • 1024 views
  • 6 likes
  • 4 in conversation