<?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: Rowise ratio of two or more variables with respect to a reference column in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892429#M39686</link>
    <description>Thank you very much!</description>
    <pubDate>Sat, 02 Sep 2023 13:29:41 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2023-09-02T13:29:41Z</dc:date>
    <item>
      <title>Rowise ratio of two or more variables with respect to a reference column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892413#M39681</link>
      <description>&lt;P&gt;Hi guys suppose to have the following table:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" style="height: 14.5pt; width: 48pt;"&gt;_FREQ_&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Count_1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Count_2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.5pt;"&gt;24213&lt;/TD&gt;
&lt;TD align="right"&gt;30240&lt;/TD&gt;
&lt;TD align="right"&gt;465&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.5pt;"&gt;21292&lt;/TD&gt;
&lt;TD align="right"&gt;58684&lt;/TD&gt;
&lt;TD align="right"&gt;16485&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.5pt;"&gt;11984&lt;/TD&gt;
&lt;TD align="right"&gt;4168&lt;/TD&gt;
&lt;TD align="right"&gt;332&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.5pt;"&gt;24981&lt;/TD&gt;
&lt;TD align="right"&gt;130459&lt;/TD&gt;
&lt;TD align="right"&gt;33411&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to divide Count_* column by _FREQ_rowise?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let say: 30240/2413 then 58684/21292.... for Count_1 and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 465/24213 then 16485/21292 .... for Count_2 and so on?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2023 12:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892413#M39681</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-09-02T12:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rowise ratio of two or more variables with respect to a reference column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892425#M39682</link>
      <description>&lt;P&gt;Just run a DATA step with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ratio1 = count1 / _freq_;
ratio2 = count2 / _freq_;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Sep 2023 12:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892425#M39682</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-02T12:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Rowise ratio of two or more variables with respect to a reference column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892426#M39683</link>
      <description>Thank you for your help! I have 28 columns I would like to avoid write the ratios every time</description>
      <pubDate>Sat, 02 Sep 2023 13:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892426#M39683</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-09-02T13:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Rowise ratio of two or more variables with respect to a reference column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892427#M39684</link>
      <description>&lt;P&gt;I believe we have suggested providing data in the form of working data step code so we have actual data to work with and don't have to ask questions about it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand your question I think this is what you want:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   rate1 = count_1 / _freq_;
   rate2 = count_2 / _freq_;
run;&lt;/PRE&gt;
&lt;P&gt;If you have 'many' count or other numerator variables that you want then ARRAY processing can reduce the total amount of code:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array c (*) count_1 count_2; /*&amp;lt;= list of the variables you have*/
   array rate(2) ;  /* the number in () should match the number of "count" variables*/
   do i=1 to dim(c);
       rate[i] = c[i] / _freq_;
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;Which if you had 20 count variables the only changes needed would be 1) the list (note SAS allows several list forms such as Count_1 - Count_20 if the variables are named such to simplify name lists)&lt;/P&gt;
&lt;P&gt;and 2) the number of elements in the Rate array.&lt;/P&gt;
&lt;P&gt;The array statement will create N variables named &amp;lt;name&amp;gt;1 to &amp;lt;name&amp;gt;N where N is the number in parentheses by default. Or you can explicitly name your variables with a list such as shown for the C array.&lt;/P&gt;
&lt;P&gt;The function DIM is a special function that returns the number of defined elements in an array. So can be used in a loop as shown to get each index number and select the desired element from the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2023 13:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892427#M39684</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-02T13:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Rowise ratio of two or more variables with respect to a reference column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892428#M39685</link>
      <description>&lt;P&gt;So this is your real issue.&lt;/P&gt;
&lt;P&gt;That's what arrays are for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array count {28} count1-count28;
array ratio {28} ratio1-ratio28;
do i = 1 to 28;
  ratio{i} = count{i} / _freq_;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But whenever I see such data structures, I suspect that a long layout would be much easier to work with from the beginning, even the PROC SUMMARY code would be simpler.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2023 13:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892428#M39685</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-02T13:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Rowise ratio of two or more variables with respect to a reference column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892429#M39686</link>
      <description>Thank you very much!</description>
      <pubDate>Sat, 02 Sep 2023 13:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rowise-ratio-of-two-or-more-variables-with-respect-to-a/m-p/892429#M39686</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-09-02T13:29:41Z</dc:date>
    </item>
  </channel>
</rss>

