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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

5 REPLIES 5
Milouda
Obsidian | Level 7
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?
data_null__
Jade | Level 19

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;
Ksharp
Super User

   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;

data_null__
Jade | Level 19

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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