<?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: Is it possible to obtain a single column Average without using Proc Means? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538073#M148091</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/29388"&gt;@philjones820&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is it possible to get just the single column average of a dataset output into a separate variable without using Proc Means?&lt;/P&gt;
&lt;PRE style="background-color: #ffffff; border: 0px; font-family: Consolas, 'Lucida Console', Courier, Monaco, monospace; padding: 0px; top: 0px; left: -1000px; margin: 0px; white-space: pre; font-size: 16px; color: #020202; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; position: fixed;"&gt;PROC IMPORT DBMS=xlsx OUT=more_rate  replace&lt;BR /&gt;  DATAFILE="/folders/myfolders/sasuser.v94/baseball_more_rate.xlsx";&lt;BR /&gt;  GETNAMES=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data more_avg2;&lt;BR /&gt;set work.more_rate;&lt;BR /&gt;TotalOBP=sum(OBP);&lt;BR /&gt;AverageOBP=TotalOBP/217;&lt;BR /&gt;drop TotalOBP;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Certainly, an invalid restriction. Why not use PROC MEANS? It is one of the fundamental SAS procedures that everyone using SAS should know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=more_avg noprint;
    var obp;
    output out=_stats_ mean=averageobp;
run;

data want;
    if _n_=1 then set _stats_;
    set more_avg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 24 Feb 2019 12:37:56 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-02-24T12:37:56Z</dc:date>
    <item>
      <title>Is it possible to obtain a single column Average without using Proc Means?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538035#M148078</link>
      <description>&lt;P&gt;Is it possible to get just the single column average of a dataset output into a separate variable without using Proc Means?. I need to obtain the average of the OBP column in the attached spreadsheet( see Column G highlighted with an average of 0.337829493 in cell Q10) and then append it to the end of that same dataset. It can be done in Excel successfully but when I average it in SAS, I get the average for each individual player in the data set and just need that one combined OBP average of &lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;0.337829493&amp;nbsp; as a variable &lt;/SPAN&gt;to append it to the original data set. My code is listed below. Also what would be best to use to append it, Would I just use PROC APPEND?&amp;nbsp; Thanks in advance for any help with this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT DBMS=xlsx OUT=more_rate  replace
  DATAFILE="/folders/myfolders/sasuser.v94/baseball_more_rate.xlsx";
  GETNAMES=YES;
RUN;

data more_avg2;
set work.more_rate;
TotalOBP=sum(OBP);
AverageOBP=TotalOBP/217;
drop TotalOBP;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE style="background-color: #ffffff; border: 0px; font-family: Consolas, 'Lucida Console', Courier, Monaco, monospace; padding: 0px; top: 0px; left: -1000px; margin: 0px; white-space: pre; font-size: 16px; color: #020202; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; position: fixed;"&gt;PROC IMPORT DBMS=xlsx OUT=more_rate  replace&lt;BR /&gt;  DATAFILE="/folders/myfolders/sasuser.v94/baseball_more_rate.xlsx";&lt;BR /&gt;  GETNAMES=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data more_avg2;&lt;BR /&gt;set work.more_rate;&lt;BR /&gt;TotalOBP=sum(OBP);&lt;BR /&gt;AverageOBP=TotalOBP/217;&lt;BR /&gt;drop TotalOBP;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;PRE style="background-color: #ffffff; border: 0px; font-family: Consolas, 'Lucida Console', Courier, Monaco, monospace; padding: 0px; top: 0px; left: -1000px; margin: 0px; white-space: pre; font-size: 16px; color: #020202; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; position: fixed;"&gt;PROC IMPORT DBMS=xlsx OUT=more_rate  replace&lt;BR /&gt;  DATAFILE="/folders/myfolders/sasuser.v94/baseball_more_rate.xlsx";&lt;BR /&gt;  GETNAMES=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data more_avg2;&lt;BR /&gt;set work.more_rate;&lt;BR /&gt;TotalOBP=sum(OBP);&lt;BR /&gt;AverageOBP=TotalOBP/217;&lt;BR /&gt;drop TotalOBP;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE style="background-color: #ffffff; border: 0px; font-family: Consolas, 'Lucida Console', Courier, Monaco, monospace; padding: 0px; top: 0px; left: -1000px; margin: 0px; white-space: pre; font-size: 16px; color: #020202; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; position: fixed;"&gt;PROC IMPORT DBMS=xlsx OUT=more_rate  replace&lt;BR /&gt;  DATAFILE="/folders/myfolders/sasuser.v94/baseball_more_rate.xlsx";&lt;BR /&gt;  GETNAMES=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data more_avg2;&lt;BR /&gt;set work.more_rate;&lt;BR /&gt;TotalOBP=sum(OBP);&lt;BR /&gt;AverageOBP=TotalOBP/217;&lt;BR /&gt;drop TotalOBP;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Feb 2019 00:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538035#M148078</guid>
      <dc:creator>philjones820</dc:creator>
      <dc:date>2019-02-24T00:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain a single column Average without using Proc Means?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538037#M148079</link>
      <description>&lt;P&gt;To get the average appended to every observation, you will need to go through the data twice ... once to compute the average, then a second time to append the value to each observation.&amp;nbsp; Here's a way to do that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data more_avg2;&lt;/P&gt;
&lt;P&gt;do until (done);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set more_rate end=done;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if OBP &amp;gt; . then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; numerator + obp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; denominator + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;averageOBP = numerator / denominator;&lt;/P&gt;
&lt;P&gt;drop numerator denominator;&lt;/P&gt;
&lt;P&gt;do until (done2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set more_rate end=done2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Feb 2019 00:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538037#M148079</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-24T00:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain a single column Average without using Proc Means?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538041#M148081</link>
      <description>&lt;P&gt;or this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select name into :namelist separated by ','
  from dictionary.columns
  where libname='WORK' and memname='MORE_RATE'
  ;
quit;

data more_avg2(drop=_numerator _denominator);
  length _numerator _denominator AverageOBP 8;
  retain _numerator _denominator;
  set work.more_rate end=last;

  if not missing(OBP) then
    do;
      _numerator=sum(_numerator,OBP);
      _denominator+1;
    end;
  output;
  if last then
    do;
      call missing(&amp;amp;namelist);
      if not missing(_denominator) then AverageOBP=_numerator/_denominator;
      output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Feb 2019 00:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538041#M148081</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-24T00:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain a single column Average without using Proc Means?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538042#M148082</link>
      <description>&lt;P&gt;What are you asking for?&amp;nbsp; What do you mean by "append a variable"?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to make a new variable?&amp;nbsp; Then should it be the same value on every observation?&amp;nbsp; If not then what.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically in SAS when you talk about appending you mean adding observations to an existing dataset.&amp;nbsp; If you added an observation with the mean of a variable which variable would you use to store the mean?&amp;nbsp; The same one?&amp;nbsp; But then want values should all of the other variables for that new observation have?&amp;nbsp; And then how the heck would you use it?&amp;nbsp; Now it will mess up any analysis you want to do with your current observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS datasets are not spreadsheet where you can paste values into random cells.&amp;nbsp; Why not just keep the mean in its own dataset.&lt;/P&gt;
&lt;P&gt;So let's make a new dataset called MEANS that has the mean in a variable named Q10.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=HAVE nway ;
  var OBP;
  output out=means mean=Q10 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then if you wanted to do calculations that used OBP and Q10 you could just combine&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data analysis;
   set have ;
   if _n_=1 then set means;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Feb 2019 00:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538042#M148082</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-24T00:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain a single column Average without using Proc Means?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538073#M148091</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/29388"&gt;@philjones820&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is it possible to get just the single column average of a dataset output into a separate variable without using Proc Means?&lt;/P&gt;
&lt;PRE style="background-color: #ffffff; border: 0px; font-family: Consolas, 'Lucida Console', Courier, Monaco, monospace; padding: 0px; top: 0px; left: -1000px; margin: 0px; white-space: pre; font-size: 16px; color: #020202; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; position: fixed;"&gt;PROC IMPORT DBMS=xlsx OUT=more_rate  replace&lt;BR /&gt;  DATAFILE="/folders/myfolders/sasuser.v94/baseball_more_rate.xlsx";&lt;BR /&gt;  GETNAMES=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data more_avg2;&lt;BR /&gt;set work.more_rate;&lt;BR /&gt;TotalOBP=sum(OBP);&lt;BR /&gt;AverageOBP=TotalOBP/217;&lt;BR /&gt;drop TotalOBP;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Certainly, an invalid restriction. Why not use PROC MEANS? It is one of the fundamental SAS procedures that everyone using SAS should know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=more_avg noprint;
    var obp;
    output out=_stats_ mean=averageobp;
run;

data want;
    if _n_=1 then set _stats_;
    set more_avg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Feb 2019 12:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-obtain-a-single-column-Average-without-using/m-p/538073#M148091</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-24T12:37:56Z</dc:date>
    </item>
  </channel>
</rss>

