<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Means Sum Statistic in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55925#M15612</link>
    <description>Hi Fred&lt;BR /&gt;
packaging the process, Myra and I presented (http://www2.sas.com/proceedings/sugi31/059-31.pdf) a few years ago, a solution to your problem,  with a macro&lt;BR /&gt;
&lt;BR /&gt;
The output would be something like&lt;BR /&gt;
column name, _freq_, statistic1 .... statisticN&lt;BR /&gt;
where the columns names to be analysed are passed into the macro as a list, or&lt;BR /&gt;
use "varlst = _ALL_" to analyse all numeric variables&lt;BR /&gt;
The list of statistics required, was passed as another parameter, like  stts = "n min p1 p5 p10 p25 p50 mean p75 p90 p95 p99 max std "&lt;BR /&gt;
or simplify things with "stts   = _ALL_" which will report all available statistics as documented (at that time) in online help for the OUTPUT statement of PROC MEANS. &lt;BR /&gt;
A hint of the power flexibility and simplicity of the macro might be indicated by the header of the macro:&lt;BR /&gt;
%macro better_means(&lt;BR /&gt;
      data   = &amp;amp;syslast ,&lt;BR /&gt;
      out    =   ,&lt;BR /&gt;
      print  = Y,&lt;BR /&gt;
      sort   = VARNUM,&lt;BR /&gt;
      stts   = _ALL_,&lt;BR /&gt;
      varlst = _ALL_,&lt;BR /&gt;
      clss   =  ,&lt;BR /&gt;
      wghts  =  ,&lt;BR /&gt;
      testing= no ,  /* any other value will preserve the _better_: data sets */&lt;BR /&gt;
/* default list of statistics when _all_ requested */&lt;BR /&gt;
      _stts  = N MEAN STD MIN MAX CSS CV LCLM NMISS&lt;BR /&gt;
               P1 P5 P10 P25 P50 P75 P90 P95 P99 QRANGE RANGE&lt;BR /&gt;
               PROBT STDERR SUM SUMWGT KURT SKEW T UCLM USS VAR&lt;BR /&gt;
     ); &lt;BR /&gt;
 &lt;BR /&gt;
You might notice the CLSS= parameter. This allows you to supply the list of variables to appear on a class statement.  Similarly there is a parameter to define WEIGHT.&lt;BR /&gt;
Unfortunately, the macro stored in the PDF referred above, suffered some publishing problems and a corrected version of the macro can be found in the sasCommunity.org site at &lt;A href="http://www.sascommunity.org/wiki/PROC_MEANS_-_Improve_on_the_default" target="_blank"&gt;http://www.sascommunity.org/wiki/PROC_MEANS_-_Improve_on_the_default&lt;/A&gt; &lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
    <pubDate>Tue, 27 Jul 2010 13:31:00 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-07-27T13:31:00Z</dc:date>
    <item>
      <title>Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55918#M15605</link>
      <description>Hello&lt;BR /&gt;
&lt;BR /&gt;
I am attempting to include the sum statistic with n min max std mean.&lt;BR /&gt;
Unfortunately whatever i try appears in output window and not in the output dataset.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
How can i modify the below code so it appears in score.TVMean dataset?&lt;BR /&gt;
&lt;BR /&gt;
proc means data = score.TV;&lt;BR /&gt;
output out = score.TVMean;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Fred</description>
      <pubDate>Mon, 26 Jul 2010 18:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55918#M15605</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-07-26T18:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55919#M15606</link>
      <description>The default output data has only N, MEAN, STD, MIN and MAX and cannot be changed as far as I know.  When I want output like I think you want I just do this... &lt;BR /&gt;
&lt;BR /&gt;
It works well enough.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc means noprint data = sashelp.class;&lt;BR /&gt;
   output out=stats;&lt;BR /&gt;
   output out=sum sum=;&lt;BR /&gt;
   run;&lt;BR /&gt;
data stats;&lt;BR /&gt;
   set stats sum(in=in2);&lt;BR /&gt;
   if in2 then _STAT_ = 'SUM';&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print data=stats;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 26 Jul 2010 18:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55919#M15606</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-07-26T18:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55920#M15607</link>
      <description>Thanks very much</description>
      <pubDate>Mon, 26 Jul 2010 19:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55920#M15607</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-07-26T19:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55921#M15608</link>
      <description>Hi:&lt;BR /&gt;
  You need to explicitly name the statistics in your OUTPUT statement. You can list the statistics on the PROC statement, and then refer to them in the OUTPUT statement. Like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc means noprint data = sashelp.class n sum mean;  &lt;BR /&gt;
   var age height;&lt;BR /&gt;
   class sex;&lt;BR /&gt;
   output out=stats n=acnt hcnt&lt;BR /&gt;
                    sum=asum hsum&lt;BR /&gt;
                    mean=aavg havg;   &lt;BR /&gt;
run;&lt;BR /&gt;
                                  &lt;BR /&gt;
proc print data=stats;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
and what you will get in the output is:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs  Sex  _TYPE_  _FREQ_  acnt  hcnt  asum   hsum     aavg     havg&lt;BR /&gt;
                             &lt;BR /&gt;
 1           0      19     19    19    253  1184.4  13.3158  62.3368&lt;BR /&gt;
 2    F      1       9      9     9    119   545.3  13.2222  60.5889&lt;BR /&gt;
 3    M      1      10     10    10    134   639.1  13.4000  63.9100&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
  cynthia</description>
      <pubDate>Mon, 26 Jul 2010 20:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55921#M15608</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-26T20:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55922#M15609</link>
      <description>Thanks Cynthia</description>
      <pubDate>Tue, 27 Jul 2010 11:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55922#M15609</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-07-27T11:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55923#M15610</link>
      <description>Hi Cynthia&lt;BR /&gt;
&lt;BR /&gt;
What part does class sex; play?&lt;BR /&gt;
&lt;BR /&gt;
Fred</description>
      <pubDate>Tue, 27 Jul 2010 11:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55923#M15610</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-07-27T11:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55924#M15611</link>
      <description>Hi Cynthia&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Hi Cynthia&lt;BR /&gt;
&lt;BR /&gt;
Output becomes very confusing do to loss of var names, i will have 15.&lt;BR /&gt;
How can i retain the column headings and control if i want mean for var or sum for var?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
_NAME_	_TYPE_	_FREQ_	aavg	haavg	asum	hsum&lt;BR /&gt;
	0	6	922660.25779695.5	11535961.54678173&lt;BR /&gt;
Apr_01	1	1	923775	743218	1923775	743218&lt;BR /&gt;
Feb_01	1	1	922003.5	764843	1922003.5	764843&lt;BR /&gt;
Jan_01	1	1	916867.5	817058	1916867.5	817058&lt;BR /&gt;
Jun_01	1	1	925262	758343	1925262	758343&lt;BR /&gt;
Mar_01	1	1	923923	814465	1923923	814465&lt;BR /&gt;
May_01	1	1	924130.5	780246	1924130.5	780246&lt;BR /&gt;
						&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Fred</description>
      <pubDate>Tue, 27 Jul 2010 12:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55924#M15611</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-07-27T12:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55925#M15612</link>
      <description>Hi Fred&lt;BR /&gt;
packaging the process, Myra and I presented (http://www2.sas.com/proceedings/sugi31/059-31.pdf) a few years ago, a solution to your problem,  with a macro&lt;BR /&gt;
&lt;BR /&gt;
The output would be something like&lt;BR /&gt;
column name, _freq_, statistic1 .... statisticN&lt;BR /&gt;
where the columns names to be analysed are passed into the macro as a list, or&lt;BR /&gt;
use "varlst = _ALL_" to analyse all numeric variables&lt;BR /&gt;
The list of statistics required, was passed as another parameter, like  stts = "n min p1 p5 p10 p25 p50 mean p75 p90 p95 p99 max std "&lt;BR /&gt;
or simplify things with "stts   = _ALL_" which will report all available statistics as documented (at that time) in online help for the OUTPUT statement of PROC MEANS. &lt;BR /&gt;
A hint of the power flexibility and simplicity of the macro might be indicated by the header of the macro:&lt;BR /&gt;
%macro better_means(&lt;BR /&gt;
      data   = &amp;amp;syslast ,&lt;BR /&gt;
      out    =   ,&lt;BR /&gt;
      print  = Y,&lt;BR /&gt;
      sort   = VARNUM,&lt;BR /&gt;
      stts   = _ALL_,&lt;BR /&gt;
      varlst = _ALL_,&lt;BR /&gt;
      clss   =  ,&lt;BR /&gt;
      wghts  =  ,&lt;BR /&gt;
      testing= no ,  /* any other value will preserve the _better_: data sets */&lt;BR /&gt;
/* default list of statistics when _all_ requested */&lt;BR /&gt;
      _stts  = N MEAN STD MIN MAX CSS CV LCLM NMISS&lt;BR /&gt;
               P1 P5 P10 P25 P50 P75 P90 P95 P99 QRANGE RANGE&lt;BR /&gt;
               PROBT STDERR SUM SUMWGT KURT SKEW T UCLM USS VAR&lt;BR /&gt;
     ); &lt;BR /&gt;
 &lt;BR /&gt;
You might notice the CLSS= parameter. This allows you to supply the list of variables to appear on a class statement.  Similarly there is a parameter to define WEIGHT.&lt;BR /&gt;
Unfortunately, the macro stored in the PDF referred above, suffered some publishing problems and a corrected version of the macro can be found in the sasCommunity.org site at &lt;A href="http://www.sascommunity.org/wiki/PROC_MEANS_-_Improve_on_the_default" target="_blank"&gt;http://www.sascommunity.org/wiki/PROC_MEANS_-_Improve_on_the_default&lt;/A&gt; &lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Tue, 27 Jul 2010 13:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55925#M15612</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-07-27T13:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55926#M15613</link>
      <description>I believe you have a bug with regards to CLM statistics.  The tails of the CLM statistics are determined by they way you "ask" for them.  For one-tail test request just one UCLM or LCLM for two-tailed test you request both.  &lt;BR /&gt;
&lt;BR /&gt;
I believe you coded something similar to this in your macro.&lt;BR /&gt;
[pre]&lt;BR /&gt;
   output out=LCLM LCLM=;&lt;BR /&gt;
   output out=UCLM UCML=;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
you get one-tailed CL. &lt;BR /&gt;
&lt;BR /&gt;
But if you ask for both you really wanted two-tailed CL.&lt;BR /&gt;
&lt;BR /&gt;
I use dummy variables to achieve the desired result.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
* Two-tail CLM;&lt;BR /&gt;
proc means data=sashelp.class lclm uclm;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
           The MEANS Procedure&lt;BR /&gt;
&lt;BR /&gt;
               Lower 95%       Upper 95%&lt;BR /&gt;
Variable     CL for Mean     CL for Mean&lt;BR /&gt;
----------------------------------------&lt;BR /&gt;
Age           12.5963445      14.0352344&lt;BR /&gt;
Height        59.8656709      64.8080133&lt;BR /&gt;
Weight        89.0496312     111.0030004&lt;BR /&gt;
----------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
* Incorrect one-tailed but should be two-tailed as both are requested;&lt;BR /&gt;
%inc 'better_means.sas';&lt;BR /&gt;
%better_means(stts=lclm uclm,data=sashelp.class);&lt;BR /&gt;
 &lt;BR /&gt;
Obs    VARNUM    NAME        LCLM       UCLM&lt;BR /&gt;
&lt;BR /&gt;
 1        3      Age       12.7220     13.910&lt;BR /&gt;
 2        4      Height    60.2972     64.377&lt;BR /&gt;
 3        5      Weight    90.9664    109.086&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
* Correct two-tailed CLM;&lt;BR /&gt;
proc means noprint data=sashelp.class;&lt;BR /&gt;
   output out=LCLM(drop=_dummy:) LCLM= UCLM=_dummy1-_dummy3;&lt;BR /&gt;
   output out=UCLM(drop=_dummy:) UCLM= LCLM=_dummy1-_dummy3;&lt;BR /&gt;
   run;&lt;BR /&gt;
data CLM;&lt;BR /&gt;
   set LCLM(in=in1) UCLM(in=in2);&lt;BR /&gt;
   length _STAT_ $8;&lt;BR /&gt;
   if      in1 then _STAT_='LCLM';&lt;BR /&gt;
   else if in2 then _STAT_='UCLM';&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
Obs    _TYPE_    _FREQ_      Age       Height     Weight    _STAT&lt;BR /&gt;
&lt;BR /&gt;
 1        0        19      12.5963    59.8657     89.050     LCLM&lt;BR /&gt;
 2        0        19      14.0352    64.8080    111.003     UCLM&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 27 Jul 2010 16:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55926#M15613</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-07-27T16:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Means Sum Statistic</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55927#M15614</link>
      <description>Hi:&lt;BR /&gt;
  I -think- I understand what you mean when you say&lt;BR /&gt;
&lt;B&gt;mean for var or sum for var&lt;/B&gt; -- I think you're asking what if you want mean for AGE and SUM for HEIGHT?? If so, then try the following amendment to the first code I posted. You can control the specific name that's assigned and ONLY get a statistic for 1 variable instead of for all the variables in the VAR statement by coding a slightly different construction on the OUTPUT statement...generally:&lt;BR /&gt;
&lt;B&gt;stat(varname)=newvarname.&lt;/B&gt; So in the example below, I am getting the N for AGE, the SUM for HEIGHT, the MEAN for AGE and the MEDIAN value for both numbers with the default names for the remaining 2 variables.&lt;BR /&gt;
 &lt;BR /&gt;
Consider this code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc means noprint data = sashelp.class n sum mean median;  &lt;BR /&gt;
   var age height;&lt;BR /&gt;
   class sex;&lt;BR /&gt;
   output out=stats2 n(age)=agecnt&lt;BR /&gt;
                    sum(height)=htsum &lt;BR /&gt;
                    mean(age)=ageavg&lt;BR /&gt;
                    median=;   &lt;BR /&gt;
run;&lt;BR /&gt;
                                           &lt;BR /&gt;
proc print data=stats2;&lt;BR /&gt;
  title '2) Control names selectively and only get some statistics';&lt;BR /&gt;
  title2 'N for AGE, only; SUM for HEIGHT only; MEAN for AGE, only; default names for MEDIAN';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                     &lt;BR /&gt;
Produces this output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
      2) Control names selectively and only get some statistics&lt;BR /&gt;
N for AGE, only; SUM for HEIGHT only; MEAN for AGE, only; default nam&lt;BR /&gt;
                              &lt;BR /&gt;
   Obs  Sex  _TYPE_  _FREQ_  agecnt   htsum   ageavg   Age  Height&lt;BR /&gt;
            &lt;BR /&gt;
    1           0      19      19    1184.4  13.3158  13.0   62.80&lt;BR /&gt;
    2    F      1       9       9     545.3  13.2222  13.0   62.50&lt;BR /&gt;
    3    M      1      10      10     639.1  13.4000  13.5   64.15&lt;BR /&gt;
             &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                       &lt;BR /&gt;
There's another example in the doc here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#/documentation/cdl/en/proc/61895/HTML/default/a002473544.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#/documentation/cdl/en/proc/61895/HTML/default/a002473544.htm&lt;/A&gt;&lt;BR /&gt;
   &lt;BR /&gt;
Also you asked what the CLASS statement was doing...the CLASS statement is telling PROC MEANS that I want the statistics for all the rows in my DATA= file (_TYPE_ = 0)  and that I want a separate row of statistics for SEX=F (_TYPE_=1) and a separate row of statistics for SEX=M (_TYPE_ = 1). &lt;BR /&gt;
 &lt;BR /&gt;
Using a CLASS statement allows me to set categories, in much the same way that the CLASS statement is used for PROC TABULATE -- it sets groups or categories -- so that the statistics can be calculated for the groups separate &lt;BR /&gt;
from the statistics for the whole dataset. For example, you can see that the average age for the whole group of 19 observations is 13.3158, but that the 9 females have an average age of 13.2222; while the average age for the 10 males is 13.40 -- that particular feature may not be useful to you right now, but is handy to know about. (Without the CLASS statement, you would only get the _TYPE_=0 row in the output dataset.)&lt;BR /&gt;
                  &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 28 Jul 2010 01:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Means-Sum-Statistic/m-p/55927#M15614</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-28T01:33:27Z</dc:date>
    </item>
  </channel>
</rss>

