<?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: How to multiply across rows? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639286#M190144</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95638"&gt;@UniversitySas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Quick question - what does the **dim(col) do?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;dim(col)&lt;/FONT&gt; is the number of elements in the array &lt;FONT face="courier new,courier"&gt;col&lt;/FONT&gt;, i.e. 100, and ** is the exponentiation operator. The hundredth root of the product (=the geometric mean, if applicable) is raised to the hundredth power to retrieve the product.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;In this case, however, I may potentially have a final negative value across each row, so I don't think geometric mean will work here.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Are you aware of a work around?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A "final negative value" -- do you mean that only the last factor, col100, might be negative?&lt;/P&gt;
&lt;P&gt;If so, you can modify the formula as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_variable=sign(col100)*geomean(of col1-col99, abs(col100))**100+10;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This would be valid irrespective of the sign of col100, as long as col1, ..., col99 are non-negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If negative values could occur anywhere, then use a DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array col[100];
new_variable=1;
do _n_=1 to 100;
  new_variable=new_variable*col[_n_];
end;
new_variable+10;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 12 Apr 2020 10:39:24 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2020-04-12T10:39:24Z</dc:date>
    <item>
      <title>How to multiply across rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639277#M190137</link>
      <description>&lt;P&gt;Suppose I have 100 columns, sorted by id and time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My cols are conveniently named col1, col2, ..., col100.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems like a really stupid question, but how would I create a new variable which multiples all the columns, and then adds 10 at the end?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using do loops, but it just confused me. I know I can just manually type it out, but&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I want:&lt;/P&gt;&lt;P&gt;new_variable = (col1)x(col2)x...x(col100)+10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 09:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639277#M190137</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-04-12T09:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply across rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639279#M190138</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95638"&gt;@UniversitySas&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0ywq67uqarnnen135hhs9gcsuv0.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;GEOMEAN function&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array col[100];
new_variable=geomean(of col[*])**dim(col)+10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;provided that none of the factors is negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shorter without array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
new_variable=geomean(of col1-col100)**100+10;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Apr 2020 10:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639279#M190138</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-12T10:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply across rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639281#M190139</link>
      <description>&lt;P&gt;Quick question - what does the **dim(col) do?&lt;BR /&gt;&lt;BR /&gt;In this case, however, I may potentially have a final negative value across each row, so I don't think geometric mean will work here.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Are you aware of a work around?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 10:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639281#M190139</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-04-12T10:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply across rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639286#M190144</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95638"&gt;@UniversitySas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Quick question - what does the **dim(col) do?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;dim(col)&lt;/FONT&gt; is the number of elements in the array &lt;FONT face="courier new,courier"&gt;col&lt;/FONT&gt;, i.e. 100, and ** is the exponentiation operator. The hundredth root of the product (=the geometric mean, if applicable) is raised to the hundredth power to retrieve the product.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;In this case, however, I may potentially have a final negative value across each row, so I don't think geometric mean will work here.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Are you aware of a work around?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A "final negative value" -- do you mean that only the last factor, col100, might be negative?&lt;/P&gt;
&lt;P&gt;If so, you can modify the formula as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_variable=sign(col100)*geomean(of col1-col99, abs(col100))**100+10;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This would be valid irrespective of the sign of col100, as long as col1, ..., col99 are non-negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If negative values could occur anywhere, then use a DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array col[100];
new_variable=1;
do _n_=1 to 100;
  new_variable=new_variable*col[_n_];
end;
new_variable+10;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Apr 2020 10:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639286#M190144</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-12T10:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply across rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639365#M190203</link>
      <description>thank you, this works perfectly.</description>
      <pubDate>Sun, 12 Apr 2020 21:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-multiply-across-rows/m-p/639365#M190203</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-04-12T21:22:06Z</dc:date>
    </item>
  </channel>
</rss>

