<?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: Obtain the mean from two or more columns using SQL and put it as a new column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926157#M364447</link>
    <description>&lt;P&gt;Hi Tom:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your answer. Yeah, you are perfectly right, four observations for each variable:&lt;/P&gt;
&lt;P&gt;data have:&lt;/P&gt;
&lt;TABLE border="0" width="236px" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;id&amp;quot;}"&gt;id&lt;/TD&gt;
&lt;TD width="53.8667px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;South&amp;quot;}"&gt;South&lt;/TD&gt;
&lt;TD width="52.9167px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;North&amp;quot;}"&gt;North&lt;/TD&gt;
&lt;TD width="41.8667px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;east&amp;quot;}"&gt;east&lt;/TD&gt;
&lt;TD width="46.55px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;west&amp;quot;}"&gt;west&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;1&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;2&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;12&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;2&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;3&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;.&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;11&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;3&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;2&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;12&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;6&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;13&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using sql i would like to obtain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="17" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;id&amp;quot;}"&gt;id&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;South&amp;quot;}"&gt;South&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;North&amp;quot;}"&gt;North&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;mean_south_north&amp;quot;}"&gt;mean_south_north&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;SD_south_north&amp;quot;}"&gt;SD_south_north&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;east&amp;quot;}"&gt;east&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;west&amp;quot;}"&gt;west&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;mean_east_west&amp;quot;}"&gt;mean_east_west&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;SD_east_west&amp;quot;}"&gt;SD_east_west&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;1&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;9&lt;/TD&gt;
&lt;TD align="center"&gt;11,125&lt;/TD&gt;
&lt;TD align="center"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;.&amp;quot;}"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;11&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;3&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;13&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where mean_south_north contains the arithmetic average, known as mean, from every observation in the columns South and North, in &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;BLUE BOLD&lt;/STRONG&gt;&lt;/FONT&gt;, as follows: 2, 3, 2, 6, 4, 4, 4; using the same thinking, SD_south_north contains the standard deviation from &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;BLUE BOLD&lt;/STRONG&gt;&lt;/FONT&gt; data, from the 4 observations and variables South and North.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Apr 2024 14:29:27 GMT</pubDate>
    <dc:creator>jonatan_velarde</dc:creator>
    <dc:date>2024-04-27T14:29:27Z</dc:date>
    <item>
      <title>Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926112#M364415</link>
      <description>&lt;P&gt;i have this data corresponding to many participants, and were collected data from them in different locations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0"&gt;&lt;COLGROUP width="22"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="43"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="66"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="117"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="102"&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="17" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;id&amp;quot;}"&gt;id&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;South&amp;quot;}"&gt;South&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;North&amp;quot;}"&gt;North&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;east&amp;quot;}"&gt;east&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;west&amp;quot;}"&gt;west&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;1&lt;/TD&gt;
&lt;TD align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;3&lt;/TD&gt;
&lt;TD align="center"&gt;.&lt;/TD&gt;
&lt;TD align="center"&gt;11&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;3&lt;/TD&gt;
&lt;TD align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;6&lt;/TD&gt;
&lt;TD align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;13&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;now i need to obtain the mean ( or average) of all of them and put it into columns, as well as standard deviation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Repair that both mean and standard deviation are considering all observations, in sql i don't want to divide the sum by the number of the observations, is not fashion LOL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i would like to obtain this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0"&gt;&lt;COLGROUP width="22"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="43"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="66"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="117"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="102"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="37"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="39"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="117"&gt;&lt;/COLGROUP&gt; &lt;COLGROUP width="102"&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="17" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;id&amp;quot;}"&gt;id&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;South&amp;quot;}"&gt;South&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;North&amp;quot;}"&gt;North&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;mean_south_north&amp;quot;}"&gt;mean_south_north&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;SD_south_north&amp;quot;}"&gt;SD_south_north&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;east&amp;quot;}"&gt;east&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;west&amp;quot;}"&gt;west&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;mean_east_west&amp;quot;}"&gt;mean_east_west&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;SD_east_west&amp;quot;}"&gt;SD_east_west&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;1&lt;/TD&gt;
&lt;TD align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;9&lt;/TD&gt;
&lt;TD align="center"&gt;11,125&lt;/TD&gt;
&lt;TD align="center"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;3&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;.&amp;quot;}"&gt;.&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;11&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;3&lt;/TD&gt;
&lt;TD align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;6&lt;/TD&gt;
&lt;TD align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;13&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the first mean comes from the observations obtained in south and north, and the second, on east and west. as well their respective standard deviations.&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 23:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926112#M364415</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-26T23:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926117#M364420</link>
      <description>&lt;P&gt;Not a SQL solution but using PROC TRANSPOSE and PROC MEANS.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data loc;
	input id South North east west;
	datalines;
1 2 4 12 9
2 3 . 11 10
3 2 4 12 10
4 6 4 13 12
;

proc transpose data = loc out = locLong(rename = (_NAME_ = Location COL1 = Response));
	by id;
run;

proc means data = locLong noprint;
	var Response;
	where Location in ("South", "North");
	output  out = southNorth(drop = _TYPE_ _FREQ_) mean = stddev = / autoname;
run;

proc means data = locLong noprint;
	var Response;
	where Location in ("east", "west");
	output  out = eastWest(drop = _TYPE_ _FREQ_) mean = stddev = / autoname;
run;

data locFinal;
	retain mean_south_north SD_south_north;
	merge loc southNorth(rename = (Response_Mean = meansouth_north Response_StdDev = SDsouth_north)) eastWest(rename = (Response_Mean = meaneast_west Response_StdDev = SDeast_west));
	mean_south_north + meansouth_north;
	SD_south_north + SDsouth_north;
	mean_east_west + meaneast_west;
	SD_east_west + SDeast_west;
	drop meansouth_north SDsouth_north meaneast_west SDeast_west;
run;

proc print data = locFinal;
	var id South North mean_south_north SD_south_north east west mean_east_west SD_east_west;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Apr 2024 01:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926117#M364420</guid>
      <dc:creator>dpalmer1</dc:creator>
      <dc:date>2024-04-27T01:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926121#M364424</link>
      <description>unfortunately i need sql code, because i will use this code in a database containing more that 500 columns, so thanks for the effort, I'm sure someone will use it..</description>
      <pubDate>Sat, 27 Apr 2024 01:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926121#M364424</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T01:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926123#M364425</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/50712"&gt;@jonatan_velarde&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;unfortunately i need sql code, because i will use this code in a database containing more that 500 columns, so thanks for the effort, I'm sure someone will use it..&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please provide as much as you can all relevant information upfront.&lt;/P&gt;
&lt;P&gt;- What database please?&lt;/P&gt;
&lt;P&gt;- What data volume (number of rows in the table)?&lt;/P&gt;
&lt;P&gt;- 500 columns in a single table?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Is there some group id in your source table? I don't expect that you want a single aggregated value for all rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;- Please try to share representative data&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;- Please share this data via data step code that generates it so we can spend the time answering your question instead of preparing sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 01:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926123#M364425</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-27T01:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926124#M364426</link>
      <description>&lt;P&gt;i found A&amp;nbsp; clue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *, &lt;BR /&gt;sum(cost + best) as sum1, &lt;BR /&gt;mean(cost best) as mean1, &lt;BR /&gt;std(cost + best) as sd1, &lt;BR /&gt;sum(west + east) as sum2,&lt;BR /&gt;mean(west + east) as mean2,&lt;BR /&gt;std(west + east) as sd2&lt;BR /&gt;from have;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but i cant get the correct &lt;STRONG&gt;mean.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;thanks in advance&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 02:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926124#M364426</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T02:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926126#M364427</link>
      <description>&lt;P&gt;I do not understand what you want, please describe in much more detail.&lt;/P&gt;
&lt;P&gt;On your first observation the value of South is 2 and of North is 4.&amp;nbsp; The mean of 2 and 4 is exactly 3.&amp;nbsp; So why do you have&amp;nbsp; 3.57... as the mean on that observation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to treat North and South as the same variable then make them the same variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's convert your LISTING into an actual DATASET.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id South North east west ;
cards;
1 2 4 12 9
2 3 . 11 10
3 2 4 12 10
4 6 4 13 12
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One way to make NORTH/SOUTH and EAST/WEST into the same variables is to just stack the two together.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select mean(north_south) as mean_north_south
     , mean(east_west) as mean_east_west
from 
(select north as north_south
      , east as east_west 
 from have
 union all 
 select south as north_south
      , west as east_west
 from have
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt; mean_north_    mean_east_
       south          west
--------------------------
    3.571429        11.125

&lt;/PRE&gt;
&lt;P&gt;But if you really have 500 variables that is going to extremely painful to code in PROC SQL.&lt;/P&gt;
&lt;P&gt;Why not just fix the data structure first.&amp;nbsp; Then it will be easier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc transpose data=have out=tall;
  by id;
  var south -- west ;
run;

proc format ;
 value $nsew  
   'North','north','South','south'='North-South'
   'East','east','West','west'='East-West'
  ;
run;

proc means data=tall mean std;
  class _name_;
  format _name_ $nsew.;
  var col1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;The MEANS Procedure

            Analysis Variable : COL1

NAME OF
FORMER           N
VARIABLE       Obs            Mean         Std Dev
--------------------------------------------------
North-South      8       3.5714286       1.3972763

East-West        8      11.1250000       1.3562027
--------------------------------------------------
&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Apr 2024 04:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926126#M364427</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T04:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926129#M364429</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/50712"&gt;@jonatan_velarde&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i found A&amp;nbsp; clue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *, &lt;BR /&gt;sum(cost + best) as sum1, &lt;BR /&gt;mean(cost best) as mean1, &lt;BR /&gt;std(cost + best) as sd1, &lt;BR /&gt;sum(west + east) as sum2,&lt;BR /&gt;mean(west + east) as mean2,&lt;BR /&gt;std(west + east) as sd2&lt;BR /&gt;from have;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but i cant get the correct &lt;STRONG&gt;mean.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;thanks in advance&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your picture of the data doesn't show variables COST or BEST. So why are you including them here?&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 06:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926129#M364429</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-27T06:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926131#M364431</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id South North east west ;
cards;
1 2 4 12 9
2 3 . 11 10
3 2 4 12 10
4 6 4 13 12
;
proc sql;
create table want as
select id,South ,North ,
(select mean(South) from (select South  from have union all select North from have)) as mean_south_north	,
(select std(South) from (select South  from have union all select North from have)) as SD_south_north,
east,west,
(select mean(east) from (select east  from have union all select west from have)) as mean_east_west	,
(select std(east) from (select east  from have union all select west from have)) as SD_east_west
from have;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Apr 2024 06:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926131#M364431</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-04-27T06:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926139#M364436</link>
      <description>&lt;P&gt;If your database has 500 columns and you need to do this on all 500 (in pairs), SQL is probably the worst tool to choose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC MEANS/PROC SUMMARY will produce the means or sums for all 500 variables, you can then in a subsequent data step combine the pairs of means (weighting properly) and pairs of standard deviations (weighting properly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also see &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1xya7vlvr6surn182ou6zrsf5wk.htm#n1lgrh9srljz4in17t789ce2vffx" target="_self"&gt;In Database Processing&amp;nbsp; for PROC MEANS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let all_names = &amp;lt;your 500 variable names&amp;gt;;

proc means data=yourdatabasetable noprint;
    var &amp;amp;all_names;
    output out=stats sum= n= stddev=/autoname;
run;

proc sql noprint;
    select cats(name,'_sum') into :sums separated by ' ' from dictionary.columns where lowcase(name) ? '_sum'
        and libname="WORK" and memname="STATS" order by varnum;
    select cats(name,'n') into :ns separated by ' ' from dictionary.columns where lowcase(name) ? '_n' 
        and libname="WORK" and memname="STATS" order by varnum;
    select cats(name,'stddev') into :stds separated by ' ' from dictionary.columns where lowcase(name) ? '_stddev' 
        and libname="WORK" and memname="STATS" order by varnum;
quit;

data final;
    set stats;
    array _s &amp;amp;sums;
    array _n &amp;amp;ns;
    array std &amp;amp;stds;
    array combined_mean mean1-mean500;
    array combined_std std1-std500;
    do i=1 to dim(_n) by 2;
        combined_mean(i)=sum(_s(i),s(i+1))/sum(_n(i),_n(i+1));
        combined_std(i)= /* Formula is at https://www.statology.org/weighted-standard-deviation-excel/ */
            /* I'm not going to program it now */ ;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 11:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926139#M364436</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-27T11:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926141#M364437</link>
      <description>Hi there!!!&lt;BR /&gt;Only need sql because is resumed and efficient.&lt;BR /&gt;&lt;BR /&gt;The database i posted as example will let me do the job for the other. that's why i showed you this here.&lt;BR /&gt;&lt;BR /&gt;Thank you</description>
      <pubDate>Sat, 27 Apr 2024 11:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926141#M364437</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T11:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926142#M364438</link>
      <description>The MEANS Procedure&lt;BR /&gt;&lt;BR /&gt;            Analysis Variable : COL1&lt;BR /&gt;&lt;BR /&gt;NAME OF&lt;BR /&gt;FORMER           N&lt;BR /&gt;VARIABLE       Obs            Mean         Std Dev&lt;BR /&gt;--------------------------------------------------&lt;BR /&gt;North-South      "7"     3.5714286       1.3972763&lt;BR /&gt;&lt;BR /&gt;East-West        8      11.1250000       1.3562027&lt;BR /&gt;--------------------------------------------------&lt;BR /&gt;&lt;BR /&gt;There are only seven information for the first mean.&lt;BR /&gt;&lt;BR /&gt;It is needed to find the whole mean, from all the observations contained in both columns&lt;BR /&gt;</description>
      <pubDate>Sat, 27 Apr 2024 11:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926142#M364438</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T11:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926143#M364439</link>
      <description>The example above contains all the information needed to be replied in a big data base. Thank you for your comprehension.</description>
      <pubDate>Sat, 27 Apr 2024 11:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926143#M364439</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T11:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926154#M364444</link>
      <description>&lt;P&gt;So your terminology is confused, which is making it hard for you to explain your request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATASETS consist of OBSERVATIONS and VARIABLES.&amp;nbsp; Your example dataset has only 4 observations and 5 variables.&amp;nbsp; If you want to take the mean of all of the VALUES in both variables then that is what I showed you how to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the count of the number of non missing values from PROC MEANS then ask for it.&amp;nbsp; It can also tell you the number of missing values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=tall n nmiss mean std;
  class _name_;
  format _name_ $nsew.;
  var col1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;The MEANS Procedure

                   Analysis Variable : COL1

NAME OF
FORMER           N             N
VARIABLE       Obs     N    Miss            Mean         Std Dev
----------------------------------------------------------------
North-South      8     7       1       3.5714286       1.3972763

East-West        8     8       0      11.1250000       1.3562027
----------------------------------------------------------------
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 14:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926154#M364444</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T14:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926157#M364447</link>
      <description>&lt;P&gt;Hi Tom:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your answer. Yeah, you are perfectly right, four observations for each variable:&lt;/P&gt;
&lt;P&gt;data have:&lt;/P&gt;
&lt;TABLE border="0" width="236px" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;id&amp;quot;}"&gt;id&lt;/TD&gt;
&lt;TD width="53.8667px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;South&amp;quot;}"&gt;South&lt;/TD&gt;
&lt;TD width="52.9167px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;North&amp;quot;}"&gt;North&lt;/TD&gt;
&lt;TD width="41.8667px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;east&amp;quot;}"&gt;east&lt;/TD&gt;
&lt;TD width="46.55px" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;west&amp;quot;}"&gt;west&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;1&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;2&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;12&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;2&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;3&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;.&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;11&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;3&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;2&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;12&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="17" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="53.8667px" align="center"&gt;6&lt;/TD&gt;
&lt;TD width="52.9167px" align="center"&gt;4&lt;/TD&gt;
&lt;TD width="41.8667px" align="center"&gt;13&lt;/TD&gt;
&lt;TD width="46.55px" align="center"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using sql i would like to obtain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="17" align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;id&amp;quot;}"&gt;id&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;South&amp;quot;}"&gt;South&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;North&amp;quot;}"&gt;North&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;mean_south_north&amp;quot;}"&gt;mean_south_north&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;SD_south_north&amp;quot;}"&gt;SD_south_north&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;east&amp;quot;}"&gt;east&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;west&amp;quot;}"&gt;west&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;mean_east_west&amp;quot;}"&gt;mean_east_west&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;SD_east_west&amp;quot;}"&gt;SD_east_west&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;1&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;9&lt;/TD&gt;
&lt;TD align="center"&gt;11,125&lt;/TD&gt;
&lt;TD align="center"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;2&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-value="{ &amp;quot;1&amp;quot;: 2, &amp;quot;2&amp;quot;: &amp;quot;.&amp;quot;}"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;11&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;3&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center"&gt;10&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="17" align="center"&gt;4&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;3,57142857142857&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,39727626201154&lt;/TD&gt;
&lt;TD align="center"&gt;13&lt;/TD&gt;
&lt;TD align="center"&gt;12&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;11,125&lt;/TD&gt;
&lt;TD align="center" data-sheets-formula="=R[-1]C"&gt;1,35620268186054&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where mean_south_north contains the arithmetic average, known as mean, from every observation in the columns South and North, in &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;BLUE BOLD&lt;/STRONG&gt;&lt;/FONT&gt;, as follows: 2, 3, 2, 6, 4, 4, 4; using the same thinking, SD_south_north contains the standard deviation from &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;BLUE BOLD&lt;/STRONG&gt;&lt;/FONT&gt; data, from the 4 observations and variables South and North.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 14:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926157#M364447</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T14:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926160#M364450</link>
      <description>&lt;P&gt;I already showed you how to do that.&amp;nbsp; You have to put those two "columns" of North and South into one "column" so that you can then use the MEAN() (or as it is commonly called in many SQL dialects AVERAGE()) aggregate function.&amp;nbsp; If your SQL dialect supports it you could also use a STD() aggregate function (by whatever name your SQL dialect chooses to use for it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try crafting your own logic for generating statistics.&lt;/P&gt;
&lt;P&gt;The mean is just the sum over the count. So that is simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(sum(south) + sum(north))/(count(south)+count(north)) as mean_south_north&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the formula for the standard deviation is much more complicated.&amp;nbsp; You would need to remerge the mean back onto every observation, find the difference, etc. etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also why the heck do you want the same value repeated onto every observation.&lt;/P&gt;
&lt;P&gt;Where are you going with this?&lt;/P&gt;
&lt;P&gt;Also how did you end up with that input data structured where you have the values for a single variable split into two variables?&amp;nbsp; It would be much easier in SQL if the data was structured with three variables (ID, DIRECTION, COUNT) and 16 observations instead of 5 variables and 4 observations.&amp;nbsp;&amp;nbsp;&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;</description>
      <pubDate>Sat, 27 Apr 2024 16:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926160#M364450</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T16:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926179#M364467</link>
      <description>&lt;P&gt;Thank you for your correct answer, now ill answer you some questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also why the heck do you want the same value repeated onto every observation.&lt;/P&gt;
&lt;P&gt;Where are you going with this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde" color="#FF0000"&gt;&lt;STRONG&gt;IT IS NOT YOUR BUSINESS!, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also how did you end up with that input data structured where you have the values for a single variable split into two variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde" color="#FF0000"&gt;YES, NOW I CAN WORK WITH MORE THAN 1000 VARIABLES&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be much easier in SQL if the data was structured with three variables (ID, DIRECTION, COUNT) and 16 observations instead of 5 variables and 4 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;IT WOULD BE EASIER TO KEEP THE STRUCTURE OF QUE QUESTION, AND MOVE ON!&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input id South North east west ;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 4 12 9&lt;BR /&gt;2 3 . 11 10&lt;BR /&gt;3 2 4 12 10&lt;BR /&gt;4 6 4 13 12&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *, &lt;BR /&gt;sum(south + north) as sum_south_north, &lt;BR /&gt;(sum(south) + sum(north))/(count(south)+count(north)) as mean_south_north, &lt;BR /&gt;std(south + north) as sd_south_north, &lt;BR /&gt;sum(west + east) as sum_west_east, &lt;BR /&gt;(sum(west) + sum(east))/(count(west)+count(east)) as mean_west_east, &lt;BR /&gt;std(west + east) as sd_south_north&lt;BR /&gt;from have;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;proc print data = want;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 18:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926179#M364467</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T18:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926180#M364468</link>
      <description>&lt;P&gt;The code you posted will not work (at least for the way you explained the problem).&lt;/P&gt;
&lt;P&gt;The problem is here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum(south + north) as sum_south_north&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At least one of your example observations had a missing value for one of those two variables.&amp;nbsp; So the addition operator will return a missing value.&amp;nbsp; Meaning that the non-missing value will not contribute to the total.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is what you wanted then your explanation of what you wanted needs to be re-worded.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 19:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926180#M364468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T19:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926181#M364469</link>
      <description>sure!</description>
      <pubDate>Sat, 27 Apr 2024 19:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926181#M364469</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T19:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926182#M364470</link>
      <description>&lt;P&gt;If you did want to ignore&amp;nbsp; observations where at least one of the variables is missing then you could just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mean(south + north)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Possibly dividing by 2 to account for the fact that two values were used to calculate each value passed to the MEAN() aggregate function.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 20:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926182#M364470</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T20:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the mean from two or more columns using SQL and put it as a new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926185#M364472</link>
      <description>&lt;P&gt;very impressive coding, thank you very much for it!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now my question would be how to apply your code to more than 2 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can it be possible??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 22:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-mean-from-two-or-more-columns-using-SQL-and-put-it-as/m-p/926185#M364472</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2024-04-27T22:33:07Z</dc:date>
    </item>
  </channel>
</rss>

