<?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: Multiplying Only When Field Is Populated in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939746#M368952</link>
    <description>Thank you!</description>
    <pubDate>Sat, 17 Aug 2024 14:48:23 GMT</pubDate>
    <dc:creator>rick_b</dc:creator>
    <dc:date>2024-08-17T14:48:23Z</dc:date>
    <item>
      <title>Multiplying Only When Field Is Populated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939739#M368946</link>
      <description>&lt;P&gt;I am trying to find a way to multiply a series of N variables. Each line has a different number of variables present. The first field is name and the second indicates the number of times that a multiplicative variable subsequently appears:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data my_data;&lt;BR /&gt;input name number_observations var1 var2 var3 var4 var5;&lt;BR /&gt;cards;&lt;BR /&gt;Ed 3 2 1 4 . .&lt;BR /&gt;Mary 5 2 1 2 3 5&lt;BR /&gt;Vince 1 3 . . . .&lt;BR /&gt;Mike 2 4 13 . . .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output:&lt;/P&gt;&lt;P&gt;Ed 3 2 1 4 . . &lt;STRONG&gt;8 (e.g., 2*1*4)&lt;/STRONG&gt;&lt;BR /&gt;Mary 5 2 1 2 3 5 &lt;STRONG&gt;60 (e.g., 2*1*2*3*5)&lt;/STRONG&gt;&lt;BR /&gt;Vince 1 3 . . . . &lt;STRONG&gt;3 (e.g., 3)&lt;/STRONG&gt;&lt;BR /&gt;Mike 2 4 13 . . . &lt;STRONG&gt;52 (e.g., 4*13)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2024 13:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939739#M368946</guid>
      <dc:creator>rick_b</dc:creator>
      <dc:date>2024-08-17T13:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying Only When Field Is Populated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939740#M368947</link>
      <description>&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2021/05/19/implement-product-function-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2021/05/19/implement-product-function-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2024 13:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939740#M368947</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-08-17T13:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying Only When Field Is Populated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939742#M368948</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set my_data;
array vars var:,
do i = 1 to dim(vars);
  if vars{i} ne .
  then do;
    value = vars{i};
    output;
  end;
end;
keep name value;
run;

data want;
set long;
by name;
if first.name
then product = value;
else product = product * value;
if last.name;
keep name product;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Aug 2024 13:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939742#M368948</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-17T13:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying Only When Field Is Populated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939743#M368949</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465881"&gt;@rick_b&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can apply the &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-expression/m-p/123084/highlight/true#M25243" target="_blank" rel="noopener"&gt;RESOLVE-%SYSEVALF trick&lt;/A&gt; to the variable list containing the factors:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';
data want;
set my_data;
if n(of var:) then prod=input(resolve('%sysevalf('||catx('*', of var:)||')'),32.);
run;
options missing='.';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(after correcting the DATA step reading the raw data).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Inserted the IF condition to catch the trivial all-missing case.&lt;/P&gt;
&lt;P&gt;Also note the limitation of this technique (if you have thousands of factors) that the &lt;FONT face="courier new,courier"&gt;CATX(...)&lt;/FONT&gt; expression must not exceed a length of 32767 characters.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2024 14:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939743#M368949</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-08-17T14:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying Only When Field Is Populated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939746#M368952</link>
      <description>Thank you!</description>
      <pubDate>Sat, 17 Aug 2024 14:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939746#M368952</guid>
      <dc:creator>rick_b</dc:creator>
      <dc:date>2024-08-17T14:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying Only When Field Is Populated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939747#M368953</link>
      <description>Thanks, Kurt.</description>
      <pubDate>Sat, 17 Aug 2024 14:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-Only-When-Field-Is-Populated/m-p/939747#M368953</guid>
      <dc:creator>rick_b</dc:creator>
      <dc:date>2024-08-17T14:48:58Z</dc:date>
    </item>
  </channel>
</rss>

