<?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: Fill variables to reach a total in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953694#M42880</link>
    <description>&lt;P&gt;Sorry, this explanation is very scattered across different posts, and still seems to be confusing to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please put all of the explanation of the logic of this problem in one new post, that covers as clearly as you can the real situation that you are working on. I am asking for&amp;nbsp; complete and clear writing, leaving nothing out; I am not asking you to write about SAS or code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2024 17:21:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-12-16T17:21:23Z</dc:date>
    <item>
      <title>Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953664#M42872</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data DB;
  input ID :$20. Total Class1 Class2 Class3;
cards;
0001 1.34    0.2     .      .
0001   .       .    0.5     . 
0002   9      1.2    .      . 
0003   2      .    0.5      .
; 
run;&lt;/PRE&gt;
&lt;P&gt;The sum Class1-3 is &amp;lt; Total.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to get the following?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;data DB1;
  input ID :$20. Total Class1 Class2 Class3;
cards;
0001 1.34    0.2     .      .
0001   .       .    0.5     0.64 
0002   9      1.2    5      2.8 
0003   2      .    0.5      2.5
; 
run;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words, I need to reach the "Total" by adding values to class* variables from the last filled class* variable&amp;nbsp; until the last class* variable (i.e., Class3) but with the rule that each Class variable cannot have a value &amp;gt;5.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&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, 16 Dec 2024 17:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953664#M42872</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-12-16T17:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953667#M42873</link>
      <description>&lt;P&gt;More explanation is needed. In the second row, total is missing, how do you determine to add 0.64 to that row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More explanation is needed for row 1 as well.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 15:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953667#M42873</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-16T15:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953671#M42874</link>
      <description>&lt;P&gt;First, let's get rid of the redundancy and get one observation per id:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=db;
by id;
var total class:;
output out=have (drop=_type_ _freq_) max()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, sum up using an array and the OF keyword in the SUM function wherever used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array c{*} class:;
do i = 1 to dim(c) until (sum(of c{*}) ge total);
  if c{i} = . then c{i} = min(5,total - sum(of c{*}));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 15:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953671#M42874</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-16T15:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953672#M42875</link>
      <description>&lt;P&gt;Since this looks more than a little bit like the output from the request in this thread: &lt;A href="https://communities.sas.com/t5/New-SAS-User/From-long-format-to-short-data-format/m-p/953512" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/From-long-format-to-short-data-format/m-p/953512&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps it would make more sense to do this "add" BEFORE making the data set wider. At least it seem like it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which means it might also be time to talk about the complete "start" data and what the planned result might be. Things that do one step at a time from request often lead to more complex than needed results because it may be that other procedures will combine multiple steps into one.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 15:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953672#M42875</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-16T15:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953684#M42876</link>
      <description>So: 0.64 is added because 1.34-(0.2 + 0.5). Moreover 0.64 MUST (!) be added at Class3 because it is the nearest class after the last filled class that is Class2. No jumping is allowed.</description>
      <pubDate>Mon, 16 Dec 2024 16:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953684#M42876</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-12-16T16:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953685#M42877</link>
      <description>&lt;P&gt;Thank you very much Kurt for your help. Unfortunately I cannot remove the redundancy because the matrix is much more complicated than what I showed and other information is present justifying the redundancy. Moreover your code assumes that the classes before the last non empty class are all filled but it is not always the case. I will edit my question with an additional case if I can.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 17:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953685#M42877</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-12-16T17:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953690#M42878</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;So: 0.64 is added because 1.34-(0.2 + 0.5). Moreover 0.64 MUST (!) be added at Class3 because it is the nearest class after the last filled class that is Class2. No jumping is allowed.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which immediately brings up the question of what to do if the "total" still needs to be added bu the last value is a Class3, and then what if class1, class2 and class3 all have values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 is just as near to 2 as 3 last time I checked. So it appears you may have some more RULES to provide.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 16:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953690#M42878</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-16T16:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953692#M42879</link>
      <description>1) "what to do if the "total" still needs to be added but the last value is a Class3,": it is not the case. Class3 is shown to simplify the coding but I have until Class7; but in any case there is always at least one empty class after the last not empty class. The idea is to fill from the last not empty class on. &lt;BR /&gt;2)" if class1, class2 and class3 all have values" not a problem because the filling should go from the last filled on --&amp;gt;</description>
      <pubDate>Mon, 16 Dec 2024 17:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953692#M42879</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-12-16T17:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953694#M42880</link>
      <description>&lt;P&gt;Sorry, this explanation is very scattered across different posts, and still seems to be confusing to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please put all of the explanation of the logic of this problem in one new post, that covers as clearly as you can the real situation that you are working on. I am asking for&amp;nbsp; complete and clear writing, leaving nothing out; I am not asking you to write about SAS or code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 17:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953694#M42880</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-16T17:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Fill variables to reach a total</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953698#M42881</link>
      <description>Ok sure, a new post will come soon</description>
      <pubDate>Mon, 16 Dec 2024 17:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-variables-to-reach-a-total/m-p/953698#M42881</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-12-16T17:33:44Z</dc:date>
    </item>
  </channel>
</rss>

