<?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: Conditional ratio of values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891490#M352188</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for help &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. IDs in dataset2 are all unique. My point was how to compress in a single piece of code both operations: the calculations of totals (by regions 1-3) in dataset2 and the ratio calculation on records of dataset1.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You will quite likely find than an insistence on a "single piece of code" can lead to a lot of time invested and often leading to fragile processes that minor changes to your data require drastic rewrites possibly requiring more time to fix than was invested in writing the first bit of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Aug 2023 14:02:58 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-08-29T14:02:58Z</dc:date>
    <item>
      <title>Conditional ratio of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891323#M352152</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following table:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset 1&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" class="xl63" style="height: 14.5pt; width: 48pt;"&gt;Region&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Value&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Class&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;34&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;23&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;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;12&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;65&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;32&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;43&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;98&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&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;76&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;44&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&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;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;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;45&lt;/TD&gt;
&lt;TD class="xl63"&gt;4&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;38&lt;/TD&gt;
&lt;TD class="xl63"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;43&lt;/TD&gt;
&lt;TD class="xl63"&gt;4&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;5&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;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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 as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset 2&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="127px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" class="xl65" style="height: 14.5pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65" style="width: 48pt;"&gt;Region&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;4&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;5&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;6&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;7&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;8&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;9&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;10&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;11&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;12&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;13&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;14&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;15&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;16&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;17&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;18&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you want to divide each value of the column "Value" of the first dataset by the total number of corresponding "Region" class in the second dataset. Lets say: 34 will be divided by 7 because in dataset 2 there are 7 IDs from region = 1.&amp;nbsp; 23 in dataset 1 will be divided by 5 because there are 5 IDs in dataset 2 with "Region" = 2. This, will be done in dataset 1 regardless of the "Class" variable. It will be there and will not take any part into the calculation. Can anyone help me please?&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>Mon, 28 Aug 2023 13:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891323#M352152</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-28T13:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional ratio of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891404#M352153</link>
      <description>&lt;P&gt;First please provide data in the form of data step code. Like this and pasted into a text box so it is easy to copy and run.&lt;/P&gt;
&lt;PRE&gt;data two;
 input ID 	Region;
datalines;
1 	1
2 	1
3 	3
4 	2
5 	2
6 	3
7 	1
8 	2
9 	1
10 	1
11 	1
12 	3
13 	3
14 	3
15 	2
16 	1
17 	2
18 	3
;

data one;
  input Region 	Value 	Class;
datalines;
1 	34 	0
2 	23 	0
3 	12 	0
1 	65 	1
2 	32 	1
3 	43 	1
1 	98 	2
2 	76 	2
3 	44 	2
1 	1 	3
2 	2 	3
3 	3 	3
1 	45 	4
2 	38 	4
3 	43 	4
1 	0 	5
2 	0 	5
3 	0 	5
;&lt;/PRE&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;/* get a count of how many times each "region" appears
in data two*/

proc freq data=two noprint;
   tables region/out=regioncount nopercent nocum;
run;

proc sort data=one;
  by region;
run;

data want;
  merge one 
        regioncount(drop=percent)
  ;
  by region;
  ratio = value/count;
run;&lt;/PRE&gt;
&lt;P&gt;However there are some places that your description may be incomplete. You say "total number of corresponding "Region" class in the second dataset."&amp;nbsp; &lt;STRONG&gt;and &lt;/STRONG&gt;"divided by 7 because in dataset 2 there are 7 IDs from region = 1". This would be correct if and only if ID is never repeated in a Region. If there are, or could be, duplicates of ID then you need to clarify if the divisor is&amp;nbsp; "number of Id per region" or "number of records with region" as they would not be the same thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following table:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset 1&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" class="xl63" style="height: 14.5pt; width: 48pt;"&gt;Region&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Value&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;Class&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;34&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;23&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;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;12&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;65&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;32&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;43&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;98&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&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;76&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;44&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&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;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;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;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;45&lt;/TD&gt;
&lt;TD class="xl63"&gt;4&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;38&lt;/TD&gt;
&lt;TD class="xl63"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;43&lt;/TD&gt;
&lt;TD class="xl63"&gt;4&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;5&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;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;TD class="xl63"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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 as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset 2&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="127px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" class="xl65" style="height: 14.5pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65" style="width: 48pt;"&gt;Region&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;2&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;3&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;4&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;5&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;6&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;7&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;8&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;9&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;10&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;11&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;12&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;13&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;14&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;15&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;16&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;17&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.4271px" height="19" align="right" style="height: 14.5pt;"&gt;18&lt;/TD&gt;
&lt;TD width="63.9062px" class="xl65"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you want to divide each value of the column "Value" of the first dataset by the total number of corresponding "Region" class in the second dataset. Lets say: 34 will be divided by 7 because in dataset 2 there are 7 IDs from region = 1.&amp;nbsp; 23 in dataset 1 will be divided by 5 because there are 5 IDs in dataset 2 with "Region" = 2. This, will be done in dataset 1 regardless of the "Class" variable. It will be there and will not take any part into the calculation. Can anyone help me please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 22:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891404#M352153</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-28T22:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional ratio of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891407#M352154</link>
      <description>&lt;P&gt;Below a SQL option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select 
    l.region
    ,l.value
    ,l.class
    ,r.cnt
    ,l.value/r.cnt as calc_value format=f16.2
  from one l left join (select region, count(id) as cnt from two group by region) r
  on l.region=r.region
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And in case the id's in table two can be repeated but you only want to count distinct id's then below variant should work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1693268687460.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87232iAA6F34925C8278EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1693268687460.png" alt="Patrick_0-1693268687460.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select 
    l.region
    ,l.value
    ,l.class
    ,r.cnt
    ,l.value/r.cnt as calc_value format=f16.2
  from one l left join (select region, count(distinct id) as cnt from two group by region) r
  on l.region=r.region
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2023 00:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891407#M352154</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-29T00:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional ratio of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891424#M352158</link>
      <description>&lt;P&gt;Thank you very much for help &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. IDs in dataset2 are all unique. My point was how to compress in a single piece of code both operations: the calculations of totals (by regions 1-3) in dataset2 and the ratio calculation on records of dataset1.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 06:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891424#M352158</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-29T06:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional ratio of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891490#M352188</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for help &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. IDs in dataset2 are all unique. My point was how to compress in a single piece of code both operations: the calculations of totals (by regions 1-3) in dataset2 and the ratio calculation on records of dataset1.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You will quite likely find than an insistence on a "single piece of code" can lead to a lot of time invested and often leading to fragile processes that minor changes to your data require drastic rewrites possibly requiring more time to fix than was invested in writing the first bit of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 14:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-ratio-of-values/m-p/891490#M352188</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-29T14:02:58Z</dc:date>
    </item>
  </channel>
</rss>

