Help using Base SAS procedures

getting descriptive statistics with proc univariate for every deciles

Reply
Occasional Contributor
Posts: 9

getting descriptive statistics with proc univariate for every deciles

Hi, 

 

I am trying to create percentiles through Proc Univariate and I am using the below code

 

proc univariate data=abdef;
var Total_AMT;
class process;
output out = data5 pctlpre=Total_AMT_P_ pctlpts= 0.9 to 99.9 by 10 ;
run;

 

What I am also trying to do is that I want to create some standard descriptive statistics at each decile like min, max, mean, std etc. 

Could you please help as to how that can be created or will I have to use something else. 

 

Thanks,

Tej

Super User
Posts: 19,770

Re: getting descriptive statistics with proc univariate for every deciles

Posted in reply to BhararaTej

You have to first calculate the decile to group your data before you can calculate the remaining statistics.

 

 

Occasional Contributor
Posts: 9

Re: getting descriptive statistics with proc univariate for every deciles

can you elaborate on what you mean by calculating deciles. 

I thought the deciles are getting calculated in my code when i use

 

pctlpre=Total_AMT_P_  pctlpts= 0.9 to 99.9 by 10

 

I have the deciles, just need now the statistics such as min, max, mean, std

Super User
Posts: 19,770

Re: getting descriptive statistics with proc univariate for every deciles

Posted in reply to BhararaTej

Then run a proc means or univariate on your output data using the calculated decile from step 1 as your BY or CLASS variable to obtain the stats of interest. 

 

You need the deciles before you can group the data. 

Occasional Contributor
Posts: 9

Re: getting descriptive statistics with proc univariate for every deciles

The code I mentioned above gives me the below table. It doesnt provides descriptive statistics at each decile. 

for ex: min, max, mean, std for each of the 10 deciles below. 

 

If you have a code, kindly share.

 

 

ObsProcessTotal_Amt_P_0_9Total_Amt_P_10_9Total_Amt_P_20_9Total_Amt_P_30_9Total_Amt_P_40_9Total_Amt_P_50_9Total_Amt_P_60_9Total_Amt_P_70_9Total_Amt_P_80_9Total_Amt_P_90_9
1A123.46124.46125.46126.46127.46128.46129.46130.46131.46132.46
2B345.95346.95347.95348.95349.95350.95351.95352.95353.95354.95
3C4305.654306.654307.654308.654309.654310.654311.654312.654313.654314.65
Super User
Posts: 19,770

Re: getting descriptive statistics with proc univariate for every deciles

[ Edited ]
Posted in reply to BhararaTej

Oh...you first need to categorize each observation as being within a specific decile group so you can then calculate summary stats. Personally I prefer proc RANK for categorizing data. There isn't an option you can specify to get what you want. 

 

You were doing from 0.9 to 99.9 so were you trying to trim outliers? Unevenly isn't common....

 

 

Occasional Contributor
Posts: 9

Re: getting descriptive statistics with proc univariate for every deciles

i am flexible on the deciles, I think at this point in time willing to work with the default deciles as well, but hoping to get the descriptive statistics at each decile in a format where the deciles goes horizontally over the top and the statistics goes vertically in the file (min, max, mean, std) for each decile. 

 

I am guessing I will have to write some custom piece of code to write that. Will explore proc rank as well. 

 

Thanks!!

Super User
Posts: 19,770

Re: getting descriptive statistics with proc univariate for every deciles

Posted in reply to BhararaTej

Actually you may not need custom code 

Use proc RANK with 10 groups to get 10 deciles. 

The use proc tabulate to generate your summaries - this generates a report, displayed output not a dataset. If you want a dataset use PROC means or univariate and then proc transpose. So semi custom if you need a dataset with the output. 

SAS Super FREQ
Posts: 3,752

Re: getting descriptive statistics with proc univariate for every deciles

Posted in reply to BhararaTej

Look at this example for how to use PROC RANK and PROC MEANS. It is not clear to me how you want to use the CLASS variable in your example, but this should get you started:

 

proc rank data=sashelp.cars out=cars groups=10 ;
var mpg_city;
ranks Rank;
run;

proc means data=cars;
class Rank Origin;
var mpg_highway weight length;
run;
Ask a Question
Discussion stats
  • 8 replies
  • 261 views
  • 0 likes
  • 3 in conversation