<?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: Multiply column variables to create a new variable. PROC IML or SAS ARRAY? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560828#M10509</link>
    <description>&lt;P&gt;how about in a situation where the column variables have different names? As an example instead of grp1, grp2, grp3 etc the variable names are liverKO kidneyKO bladderKO heartKO lungsKO. (I am going to get to that point in the next couple of weeks in the course of my experiments, hence why i am asking).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what would the line statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct = geomean(of grp:)**5&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;look like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2019 13:18:27 GMT</pubDate>
    <dc:creator>dammie_101</dc:creator>
    <dc:date>2019-05-22T13:18:27Z</dc:date>
    <item>
      <title>Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560762#M10490</link>
      <description>&lt;P&gt;Good day everyone.&lt;/P&gt;&lt;P&gt;Please i need some advice, as well as help with something.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new variable by asking SAS to multiply the values in the cells of input columns, and repeat this process for all observations. As it in the code below...I want to ask SAS to start with obs 1 (row 1) and multiply the values of grp1 - grp5 to create new variable "rowproduct" with the result in that cell. Then it should go on to obs 2 (row 2)...etc until the end.&lt;/P&gt;&lt;P&gt;Will the IML procedure be better suited for this or will it more appropriate to use ARRAY?&lt;/P&gt;&lt;P&gt;Example code to solve this will be highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;Dami.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input TargetID	grp1	grp2	grp3	grp4	grp5;
datalines;
7314326	88103	102695	118879	82913	95039
10031881	253	255	74	36	442
7213321	3431	5344	1134	637	4054
7213330	2765	4184	1143	635	2722
7214940	447	269	11328	9417	145
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 11:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560762#M10490</guid>
      <dc:creator>dammie_101</dc:creator>
      <dc:date>2019-05-22T11:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560767#M10493</link>
      <description>&lt;P&gt;Use an array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set test;
array myarr {*} grp:;
rowproduct = 1;
do i = 1 to dim(myarr);
  rowproduct = rowproduct * coalesce(myarr{i},1);
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 May 2019 11:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560767#M10493</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-22T11:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560786#M10495</link>
      <description>&lt;P&gt;Or keep it simple:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set test;
rowproduct=grp1*grp2*grp3*grp4*grp5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A shorter alternative (especially if the product involved more than only 5 "GRP" variables) would be something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct=geomean(of grp:)**5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where all variables would be multiplied whose names start with "GRP" (use &lt;FONT face="courier new,courier"&gt;grp1-grp5&lt;/FONT&gt;&amp;nbsp;if &lt;FONT face="courier new,courier"&gt;grp:&lt;/FONT&gt; was too comprehensive) and the exponent (5) is the number of these variables. Restriction: The GEOMEAN function requires non-negative arguments. However, if missing values could occur, the exponent would need to be the number of non-missing values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct=geomean(of grp:)**n(of grp:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(The GEOMEAN function ignores missing values unlike the explicit product).&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 11:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560786#M10495</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-22T11:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560828#M10509</link>
      <description>&lt;P&gt;how about in a situation where the column variables have different names? As an example instead of grp1, grp2, grp3 etc the variable names are liverKO kidneyKO bladderKO heartKO lungsKO. (I am going to get to that point in the next couple of weeks in the course of my experiments, hence why i am asking).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what would the line statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct = geomean(of grp:)**5&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;look like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 13:18:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560828#M10509</guid>
      <dc:creator>dammie_101</dc:creator>
      <dc:date>2019-05-22T13:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560837#M10512</link>
      <description>&lt;P&gt;This works perfectly!&lt;/P&gt;&lt;P&gt;I am grateful.&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 13:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560837#M10512</guid>
      <dc:creator>dammie_101</dc:creator>
      <dc:date>2019-05-22T13:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560844#M10513</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212624"&gt;@dammie_101&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This works perfectly!&lt;/P&gt;
&lt;P&gt;I am grateful.&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Fine! Is the code clear to you, or do you need additional explanation?&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 13:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560844#M10513</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-22T13:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560848#M10514</link>
      <description>&lt;P&gt;i think i get the logic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS scans and calls in all variables from the input dataset into array procedure;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set column 'rowproduct' to an initial of 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;initiate array procedure from column 1 until last element in the array dimension;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rowproduct =&amp;gt; (a) call initial value of rowproduct...multiply this with (b) call cell values in array dimension, multiply values) until last entry;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 14:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560848#M10514</guid>
      <dc:creator>dammie_101</dc:creator>
      <dc:date>2019-05-22T14:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560883#M10518</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212624"&gt;@dammie_101&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;how about in a situation where the column variables have different names? As an example instead of grp1, grp2, grp3 etc the variable names are liverKO kidneyKO bladderKO heartKO lungsKO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what would the line statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct = geomean(of grp:)**5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If those five variables are adjacent in dataset TEST, i.e., if their variable numbers in PROC CONTENTS output of TEST (see column "#"; ideally use the VARNUM option) are consecutive and, let's say, liverKO is the first and lungsKO the last variable in that order, you can write&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct=geomean(of liverKO--lungsKO)**5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(assuming there are no missing values, as explained earlier; otherwise replace "5" by "n(of&amp;nbsp;liverKO--lungsKO)" if you want to obtain the product of the non-missing values in this case).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A similar notation (&lt;FONT face="courier new,courier"&gt;liverKO-numeric-lungsKO&lt;/FONT&gt;) would apply if the sequence of the five variables was only interrupted by character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can define an array (see the ARRAY statement in KurtBremser's post, where "grp:" would be replaced either by the list of all five variable names or, if applicable, by the variable list in the notation I've just described). Then the formula would read&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct=geomean(of myarr{*})**5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(or, again, with &lt;FONT face="courier new,courier"&gt;n(of myarr{*})&lt;/FONT&gt; as the exponent).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, if the number of factors is as small as five, I would prefer the simple definition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rowproduct=liverKO*kidneyKO*bladderKO*heartKO*lungsKO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is much easier to read, even if the COALESCE function (see KurtBremser's solution) was applied to each factor in order to ignore missing values.&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>Wed, 22 May 2019 15:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560883#M10518</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-22T15:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560970#M10523</link>
      <description>&lt;P&gt;understood.&lt;/P&gt;&lt;P&gt;I am sincerely grateful for taking time to explain to that depth of detail.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 20:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/560970#M10523</guid>
      <dc:creator>dammie_101</dc:creator>
      <dc:date>2019-05-22T20:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/561077#M10533</link>
      <description>&lt;P&gt;I am open to learning more. I absolutely would not mind additional explanation.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212624"&gt;@dammie_101&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;This works perfectly!&lt;/P&gt;&lt;P&gt;I am grateful.&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Fine! Is the code clear to you, or do you need additional explanation?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 09:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/561077#M10533</guid>
      <dc:creator>dammie_101</dc:creator>
      <dc:date>2019-05-23T09:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/561079#M10535</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set test;

array myarr {*} grp:;
/* defines an array over all variables the name of which starts with grp */
/* the dimension (*) is dynamic, dependent on the number of variables found */
/* the colon can be used as wildcard character in SAS code for variables or dataset names */
/* but can only be used at the end */

rowproduct = 1;
/* initializes the new variable, as a simple calculation on missing values would result in missing values */

do i = 1 to dim(myarr); /* upper bound depends on number of variables found */
  rowproduct = rowproduct * coalesce(myarr{i},1);
  /* coalesce() returns the first non-missing argument */
  /* prevents missing values to destroy our result */

end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 May 2019 09:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/561079#M10535</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-23T09:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply column variables to create a new variable. PROC IML or SAS ARRAY?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/561086#M10540</link>
      <description>&lt;P&gt;Thank you so very much!&lt;/P&gt;&lt;P&gt;I am deeply grateful.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 10:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiply-column-variables-to-create-a-new-variable-PROC-IML-or/m-p/561086#M10540</guid>
      <dc:creator>dammie_101</dc:creator>
      <dc:date>2019-05-23T10:47:55Z</dc:date>
    </item>
  </channel>
</rss>

