BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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)

 

 

 

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

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)

 

 

 

 

 

hhchenfx
Barite | Level 11

Thank you for your help.

HHC

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1100 views
  • 0 likes
  • 2 in conversation