Hi,
I want to create a table where each column is a variable.
Rows are Mean, Median, percentile 15, percentile 85, percentile x.
For mean and median, I can do it as below.
However, when it come to percentile, I can't specify the output name as for mean and median so I am kind of stuck.
Can you please help?
Thank you,
HHC
data have;
input v0 v1 v2 v3 v4 v5;
datalines;
1 1 0 5 6 0
1 1 0 5 7 1
2 1 0 5 7 0
4 1 1 5 6 1
5 1 0 5 6 0
6 1 1 5 9 0
7 1 0 5 2 -1
8 2 1 5 4 -1
9 2 1 5 1 0
;run;
proc univariate data=have noprint;
var v0-v5;
output out=stat_1
mean=v0-v5;run;
data stat_1; set stat_1;
statistic = 'MEAN';run;
proc univariate data=have noprint;
var v0-v5;
output out=stat_2
median=v0-v5;run;
data stat_2; set stat_2;
statistic = 'MEDIAN';run;
*I can stack one on top of the other as name are the same;
data summary; set stat_1 stat_2;run;
proc univariate data=have noprint;
var v0-v5;
output out=stat_2
pctlpts= 15
pctlname=v0-v5; *this doesn't work;
run;
If you want multiple percentiles for multiple variables see the following. Either of the Pcntlpre statements will work.
The key bit you were missing is PCNTLPRE, as in a prefix to put before things, especially when really wanting multiple percentiles. The list options a pretty limited. However I would not recommend the simple v0-v5 list if you are asking for many percentiles for many variables as it can get hard to tell where a base variable name ends and the percentile value starts.
proc univariate data=have noprint; var v0-v5; output out=stat_2 pctlpts= 15 30 pctlpre = v0 - v5 /* pctlpre = Pv0_ Pv1_ Pv2_ Pv3_ Pv4_ Pv5_ */ ; run;
If you don't really need P15 or P85 you might look at this output from Proc tabulate:
proc tabulate data=have;
var v0-v5;
table mean median p1 p10 p80 p90 p99 ,
v0-v1
;
run;
Unfortunately Tabulate only does 1, 5, 10 to 90 by 10, 95 and 99 percentiles and the quartiles ( q1=P25, q3 = P75)
If you want multiple percentiles for multiple variables see the following. Either of the Pcntlpre statements will work.
The key bit you were missing is PCNTLPRE, as in a prefix to put before things, especially when really wanting multiple percentiles. The list options a pretty limited. However I would not recommend the simple v0-v5 list if you are asking for many percentiles for many variables as it can get hard to tell where a base variable name ends and the percentile value starts.
proc univariate data=have noprint; var v0-v5; output out=stat_2 pctlpts= 15 30 pctlpre = v0 - v5 /* pctlpre = Pv0_ Pv1_ Pv2_ Pv3_ Pv4_ Pv5_ */ ; run;
If you don't really need P15 or P85 you might look at this output from Proc tabulate:
proc tabulate data=have;
var v0-v5;
table mean median p1 p10 p80 p90 p99 ,
v0-v1
;
run;
Unfortunately Tabulate only does 1, 5, 10 to 90 by 10, 95 and 99 percentiles and the quartiles ( q1=P25, q3 = P75)
Thank you for your help.
HHC
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.