Dear SAS users,
I am struggling a bit on calculating the percentiles across observations using a proc univariate.
My dataset is as follows:
V1 v2 v3 PercentileV1 Percentile V2 Percentile V3
Bank1
Bank2
I need to created the variables Percentilve V1, V2 and V3 for a defined population of banks.
Does anyone has used the proc univariate to do this?
In advance, thanks a lot,
Best regards,
Data A;
Length ID $10.;
Do i=1 To 1000;
ID=Catt('Bank_',Put(i,Z4.));
Value=Int(Ranuni(1)*1000);
Output;
End;
Drop i;
Run;
Proc Univariate Data=A NoPrint;
Var Value;
Output Out=Result PctlPre=PERC_ PctlPts=1 to 100 by 1;
Run;
Data B (Keep=ID Value Info);
Length Info $20.;
Set A;
If _N_ eq 1 Then Do;
Set Result;
End;
Array P Perc_:;
Do i=1 To Dim(P);
If Missing (Info) & Value lt P[i] Then Info=VName(P[i]);
End;
Run;
* .. only to check;
Proc Sort Data=B;
By Value;
Run;
For data in wide form (each bank in its own variable), the article "Output percentiles of multiple variables in a tabular format" contains your answer. It shows how to use PROC MEANS (near top) and PROC UNIVARIATE (scroll down).
For data in long for (banks identified by the value of a categorical variable), you can use the CLASS statement as follows:
proc means data=sashelp.class p25 p50 p75;;
class sex;
var height;
run;
You could search for the pctlpts-option: http://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_univaria...
And I think the result should bel like this:
Data A;
Do ID='BANK1','BANK2','BANK3';
Do j=0 To 100;
Output;
End;
End;
Run;
Proc Univariate Data=A NoPrint;
Var j;
By ID;
Output Out=Result PctlPre=PERC_ PctlPts=30, 70 to 85 by 5;
Run;
Data A;
Length ID $10.;
Do i=1 To 1000;
ID=Catt('Bank_',Put(i,Z4.));
Value=Int(Ranuni(1)*1000);
Output;
End;
Drop i;
Run;
Proc Univariate Data=A NoPrint;
Var Value;
Output Out=Result PctlPre=PERC_ PctlPts=1 to 100 by 1;
Run;
Data B (Keep=ID Value Info);
Length Info $20.;
Set A;
If _N_ eq 1 Then Do;
Set Result;
End;
Array P Perc_:;
Do i=1 To Dim(P);
If Missing (Info) & Value lt P[i] Then Info=VName(P[i]);
End;
Run;
* .. only to check;
Proc Sort Data=B;
By Value;
Run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.