DATA Step, Macro, Functions and more

Proc Summary Help!

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Proc Summary Help!

I intend to create the following statistics  for some continuous variable. I used Proc summary as follow

proc summary data=&dataset nway completetypes;
   class &grp/ preloadfmt;
   var &continuous;
   output out=continuous2(drop=_type_);							
   run;

this was my output.

 

         thsoutput.png

Is there any way to add to the same table the quantiles(Q1, Median and Q3)? 

thanks

 


Accepted Solutions
Solution
‎08-29-2016 08:49 AM
Respected Advisor
Posts: 3,777

Re: Proc Summary Help!

You can add output statements for each new statistic and the combine, this make the syntax easy. 

 

I used to do that but with PROC MEANS STACKODS I prefer that option.  While the data structure is not the same it is equally useful.

 

proc summary nway data=sashelp.class;
   class sex;
   var _numeric_;
   output out=stats;
   output out=median median=;
   output out=q1 q1=;
   output out=q3 q3=;
   run;
data stats;
   set stats median q1 q3 indsname=indsname;
   by sex;
   if missing(_stat_) then _stat_=scan(indsname,-1,'.');
   run;
proc print;
   run;
ods exclude all;
proc means data=sashelp.class n mean std min max median q1 q3 nway stackods;
   class sex;
   ods output summary=summary;
   run; 
ods exclude none;
proc print;
   run;

View solution in original post


All Replies
Super User
Posts: 5,260

Re: Proc Summary Help!

Occasional Contributor
Posts: 15

Re: Proc Summary Help!

I tried by listing the keywords for the statistics I want, no luck. It only produces statistics for one variable.
What is wrong in my code?
Solution
‎08-29-2016 08:49 AM
Respected Advisor
Posts: 3,777

Re: Proc Summary Help!

You can add output statements for each new statistic and the combine, this make the syntax easy. 

 

I used to do that but with PROC MEANS STACKODS I prefer that option.  While the data structure is not the same it is equally useful.

 

proc summary nway data=sashelp.class;
   class sex;
   var _numeric_;
   output out=stats;
   output out=median median=;
   output out=q1 q1=;
   output out=q3 q3=;
   run;
data stats;
   set stats median q1 q3 indsname=indsname;
   by sex;
   if missing(_stat_) then _stat_=scan(indsname,-1,'.');
   run;
proc print;
   run;
ods exclude all;
proc means data=sashelp.class n mean std min max median q1 q3 nway stackods;
   class sex;
   ods output summary=summary;
   run; 
ods exclude none;
proc print;
   run;
Super User
Posts: 9,687

Re: Proc Summary Help!


   proc univariate data=sashelp.class outtable=want noprint;
   class sex;
   var age weight height;
   run;
   proc sort data=want; by sex _var_;run;
   proc print noobs label;run;

Respected Advisor
Posts: 3,777

Re: Proc Summary Help!


Ksharp wrote:
   proc univariate data=sashelp.class outtable=want noprint;
   class sex;
   var age weight height;
   run;
   proc sort data=want; by sex _var_;run;
   proc print noobs label;run;


 

 

PROC UNIVARIATE does not support PRELOADFMT and has other CLASS statement limitations.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 321 views
  • 2 likes
  • 4 in conversation