<?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 compute the product row for each 1000 column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891275#M352105</link>
    <description>&lt;P&gt;Thank you so much! Your script worked!!&lt;/P&gt;</description>
    <pubDate>Mon, 28 Aug 2023 03:03:11 GMT</pubDate>
    <dc:creator>mango_tango_598</dc:creator>
    <dc:date>2023-08-28T03:03:11Z</dc:date>
    <item>
      <title>How to compute the product row for each 1000 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891271#M352101</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset has 1000 columns (named 'Simulation1', 'Simulation2',------, 'Simulation1000'), and each column has 28 rows. I obtain the SAS code to calculate the product row for column 1 (Simulation1).&amp;nbsp; I would like to do the same calculation for each 1000 column. Please help me to set up those calculation. Thank you very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/* DATA step method to compute the product down the rows */
data want1;
retain Prod 1 n 0; /* n = number of nonmissing */
set have end=EOF;
if ^missing(Simulation1) then do;
n + 1;
Prod = Prod * Simulation1;
end;
if EOF then do;
if n=0 then Prod=.;
put n= / prod=;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 01:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891271#M352101</guid>
      <dc:creator>mango_tango_598</dc:creator>
      <dc:date>2023-08-28T01:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the product row for each 1000 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891272#M352102</link>
      <description>&lt;P&gt;You could use arrays.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have end=eof;
  array simulation simulation1-simulation1000;
  array product [1000] _temporary_ (1000*1);
  do index=1 to dim(simulation);
     product[index]=product[index]*simulation[index];
  end;
  if eof then do;
     do index=1 to dim(simulation);
       simulation[index]=product[index];
     end;
     n = _n_;
     output;
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also convert the values to the log() and then SUM them (using PROC SUMMARY for example).&amp;nbsp; You can then convert them back into raising 10 to the power of the sum of the logs.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 02:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891272#M352102</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-28T02:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the product row for each 1000 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891273#M352103</link>
      <description>&lt;P&gt;You can make use of a &lt;EM&gt;&lt;STRONG&gt;_TEMPORARY_&lt;/STRONG&gt;&lt;/EM&gt; array, which is automatically retained, and can hold your product values.&amp;nbsp; For the last obs copy that array back to the original variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=i);
  set have  end=end_of_have;

  array prod {1000} _temporary_;
  array sim  {1000} simulation1-simulation1000;

  do i=1 to 1000;
    if not missing(sim{i}) then prod{i}=sim{i}*coalesce(prod{i},1);
  end;

  if end_of_have;
  do i=1 to 1000;
    sim{i}=prod{i};
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes you have 1,000 variables named simulation1 - simulation1000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason for the "&lt;STRONG&gt;coalesce(prod{i},1)&lt;/STRONG&gt;", is to make sure that the first multiplication is not applied to the missing value that initializes the PROD array.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 02:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891273#M352103</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-28T02:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the product row for each 1000 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891274#M352104</link>
      <description>&lt;P&gt;Thank you so much! Your script also worked too!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 03:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891274#M352104</guid>
      <dc:creator>mango_tango_598</dc:creator>
      <dc:date>2023-08-28T03:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the product row for each 1000 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891275#M352105</link>
      <description>&lt;P&gt;Thank you so much! Your script worked!!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 03:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891275#M352105</guid>
      <dc:creator>mango_tango_598</dc:creator>
      <dc:date>2023-08-28T03:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the product row for each 1000 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891276#M352106</link>
      <description>&lt;P&gt;Just to round out the available techniques, there is a reasonable array-less solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=need;
run;
data need_product (keep=_name_ product);
  set need;
  if n(of col:)&amp;gt;0 then product=geomean(of col:)**n(of col:);
run;
proc transpose data=need_product out=want (drop=_name_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Aug 2023 03:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891276#M352106</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-28T03:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the product row for each 1000 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891291#M352112</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
It is SAS/IML thing.
*/
data have;
array x{*} Simulation1-Simulation1000;
call streaminit(123);
do n=1 to 28;
 do i=1 to dim(x);
   x{i}=rand('integer',1,4);
   if rand('bern',0.2)=1 then call missing(x{i});
 end;
output;
end;
keep Simulation: ;
run;

proc iml;
use have;
read all var _num_ into x[c=vnames];
close;
want=j(nrow(x),ncol(x),.);
do i=1 to ncol(x);
 want[,i]=cuprod(x[,i]);
end;
create want from want[c=vnames];
append from want;
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Aug 2023 11:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-product-row-for-each-1000-column/m-p/891291#M352112</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-08-28T11:37:48Z</dc:date>
    </item>
  </channel>
</rss>

