<?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 Perform a ratio by classes in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Perform-a-ratio-by-classes/m-p/891240#M39636</link>
    <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose to have a dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Class&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Place&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;.....&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .....&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, you have another dataset of which you will take only the total number of rows, for example 10.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you want to divide the number of IDs in the first dataset by the total number of IDs in the second dataset, i.e., 10 but you want to do this by "Class" and "Place". How, this, can be achieved? In other words the desired output would be:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 192pt;" border="0" width="256" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl63" style="height: 14.5pt; width: 48pt;"&gt;Place&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Class&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Count&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Ratio&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;0.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;0.1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;0.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see (as an example), for place =1, there are IDs only in Class 0 and they are 3 in total. So 3/10 = 0.3. These are example numbers of the real situation. Totally I have 10 "Classes", 1 "Place" and 19.398 rows in the first dataset and 76.984 rows in the second dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&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>Sun, 27 Aug 2023 11:04:09 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2023-08-27T11:04:09Z</dc:date>
    <item>
      <title>Perform a ratio by classes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Perform-a-ratio-by-classes/m-p/891240#M39636</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose to have a dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Class&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Place&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;.....&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .....&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, you have another dataset of which you will take only the total number of rows, for example 10.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you want to divide the number of IDs in the first dataset by the total number of IDs in the second dataset, i.e., 10 but you want to do this by "Class" and "Place". How, this, can be achieved? In other words the desired output would be:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 192pt;" border="0" width="256" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl63" style="height: 14.5pt; width: 48pt;"&gt;Place&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Class&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Count&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Ratio&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;0.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;0.1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;0.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see (as an example), for place =1, there are IDs only in Class 0 and they are 3 in total. So 3/10 = 0.3. These are example numbers of the real situation. Totally I have 10 "Classes", 1 "Place" and 19.398 rows in the first dataset and 76.984 rows in the second dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&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>Sun, 27 Aug 2023 11:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Perform-a-ratio-by-classes/m-p/891240#M39636</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-27T11:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a ratio by classes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Perform-a-ratio-by-classes/m-p/891250#M39638</link>
      <description>&lt;P&gt;For problems that involve counting, your first choice ought to be PROC FREQ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
	tables class*place/noprint list sparse out=counts;
run;
data want;
    set counts(drop=percent);
    ratio=count/10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From now on, please provide data as WORKING data step code, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Class Place;
cards;
  1            0               1
  2           0               1
  3           0               1
  4           1                2
  5           2               2
  6           2               2
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2023 13:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Perform-a-ratio-by-classes/m-p/891250#M39638</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-27T13:49:55Z</dc:date>
    </item>
  </channel>
</rss>

