<?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 PROC IML - mean and standard deviation in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7178#M30</link>
    <description>Hello, I hope all is well.  I am trying to calculate a mean and standard deviation of elements in a matrix (that is the mean (and std) of all elements in a matrix), but cannot figure out if syntax exists within PROC IML.  If a matrix 3x3 matrix has 9 elements (numbered 1-9) then the mean of the matrix is 5.  I've tried a lot of options, but can't get it to work.  &lt;BR /&gt;
&lt;BR /&gt;
The backstory is that I need to translate MATLAB (which I don't have access to) code into IML, but again, can't find comparable functions.  For example, for a matrix g, the MATLAB code for std is std(g(:)) and the code for mean is mean(mean(g).  &lt;BR /&gt;
&lt;BR /&gt;
Thank you for any assistance.  Take care.&lt;BR /&gt;
&lt;BR /&gt;
Todd</description>
    <pubDate>Thu, 28 Feb 2008 22:26:02 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-02-28T22:26:02Z</dc:date>
    <item>
      <title>PROC IML - mean and standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7178#M30</link>
      <description>Hello, I hope all is well.  I am trying to calculate a mean and standard deviation of elements in a matrix (that is the mean (and std) of all elements in a matrix), but cannot figure out if syntax exists within PROC IML.  If a matrix 3x3 matrix has 9 elements (numbered 1-9) then the mean of the matrix is 5.  I've tried a lot of options, but can't get it to work.  &lt;BR /&gt;
&lt;BR /&gt;
The backstory is that I need to translate MATLAB (which I don't have access to) code into IML, but again, can't find comparable functions.  For example, for a matrix g, the MATLAB code for std is std(g(:)) and the code for mean is mean(mean(g).  &lt;BR /&gt;
&lt;BR /&gt;
Thank you for any assistance.  Take care.&lt;BR /&gt;
&lt;BR /&gt;
Todd</description>
      <pubDate>Thu, 28 Feb 2008 22:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7178#M30</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-02-28T22:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML - mean and standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7179#M31</link>
      <description>Hi Todd.&lt;BR /&gt;
Since IML is part of SAS, it does not expect roxs and columns to be part of the same data series. So there seems to be nothing as simple as in Matlab to compute such means and standard deviations ; it would have been done with the MEAN and STD functions if your data were arranged as {1 2 3 4 5 6 7 8 9}, in one row or one column only.&lt;BR /&gt;
Here are workarounds to compute means &amp;amp; standard deviations for a whole matrix.&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC IML ;&lt;BR /&gt;
	a = {1 2 3 4, 5 6 7 8, 9 10 11 12} ;&lt;BR /&gt;
	mean = a[+,+]/(NROW(a)*NCOL(a)) ;&lt;BR /&gt;
	PRINT mean ;&lt;BR /&gt;
	std = SQRT((a-mean)[##,+]/(NROW(a)*NCOL(a)-1)) ;&lt;BR /&gt;
	PRINT std ;&lt;BR /&gt;
QUIT ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards.&lt;BR /&gt;
Olivier&lt;BR /&gt;
&lt;BR /&gt;
PS : the + and  ## syntax is taken from the Example 8.1 in the SAS IML documentation (General Statistics &amp;gt; Correlation).</description>
      <pubDate>Tue, 04 Mar 2008 11:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7179#M31</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2008-03-04T11:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML - mean and standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7180#M32</link>
      <description>You can use A[:] for the mean and M[##] for sum of squares of a matrix.&lt;BR /&gt;
If you have missing values, then you need to be careful about the divisor for the standard deviation.  Try the following:&lt;BR /&gt;
proc iml;&lt;BR /&gt;
a = {. 2 3 4, 5 6 . 8, 9 10 11 12} ;&lt;BR /&gt;
mean = a[:];	&lt;BR /&gt;
numNonMissing = ncol(loc(a^=.));&lt;BR /&gt;
std = sqrt( (a-mean)[##] / (numNonMissing-1) );&lt;BR /&gt;
print mean std;</description>
      <pubDate>Fri, 29 May 2009 19:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7180#M32</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2009-05-29T19:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IML - mean and standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7181#M33</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; By the way, in SAS/IML 9.22 and beyond there are explicity MEAN and VAR functions:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect191.htm"&gt;MEAN: &lt;/A&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect191.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect191.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect323.htm"&gt;VAR: &lt;/A&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect323.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect323.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For computing the variance of each column prior to SAS/IML 9.22, see &lt;A href="http://blogs.sas.com/content/iml/2011/04/07/computing-the-variance-of-each-column-of-a-matrix/"&gt;http://blogs.sas.com/content/iml/2011/04/07/computing-the-variance-of-each-column-of-a-matrix/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Oct 2011 13:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-IML-mean-and-standard-deviation/m-p/7181#M33</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2011-10-12T13:03:40Z</dc:date>
    </item>
  </channel>
</rss>

