<?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: Summing fields with conditions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136798#M36889</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Sep 2014 15:04:11 GMT</pubDate>
    <dc:creator>brophymj</dc:creator>
    <dc:date>2014-09-09T15:04:11Z</dc:date>
    <item>
      <title>Summing fields with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136795#M36886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;TABLE border="1" class="jiveBorder" height="102" style="border: 1px solid rgb(0, 0, 0); width: 366px; height: 102px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X3&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X4&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X5&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;-10&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;-5&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;50&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;50&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;23&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;42&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;-1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;-5&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;-7&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;44&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bascially i want to perform calculation that allocates the negative values to the cells with the positive values in proportion to the split of the positive values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the above table would become:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="95" style="border: 1px solid rgb(0, 0, 0); width: 474px; height: 95px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X3&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X4&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;X5&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;=50+(-15)*(50/200)&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;=50+(-15)*(50/200)&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;=100+(-15)*(100/200)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To achive this i need to sum the negative values, the posive values and then apply a condition formula like if X1 &amp;lt;0 then X1 =0; else X1 = X1 + (sumNeg)*(X1)/(sumPos);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or something like that&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this easy to do?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 14:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136795#M36886</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2014-09-09T14:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Summing fields with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136796#M36887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want(keep=x1-x5);&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array x{*} x1-x5;&lt;/P&gt;&lt;P&gt;sum_neg=0;&lt;/P&gt;&lt;P&gt;sum_pos=0;&lt;/P&gt;&lt;P&gt;do i=1 to dim(x);&lt;/P&gt;&lt;P&gt;if x{i}&amp;lt;0 then sum_neg+x{i};&lt;/P&gt;&lt;P&gt;else sum_pos+x{i};&lt;/P&gt;&lt;P&gt;if x{i}&amp;lt;0 then x{i}=0;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;do i=1 to dim(x);&lt;/P&gt;&lt;P&gt;x{i} = x{i} + sum_neg*x{i}/sum_Pos;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 14:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136796#M36887</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-09-09T14:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Summing fields with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136797#M36888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;BR /&gt; input&amp;nbsp; var1 var2 var3 var4 var5;&lt;BR /&gt; cards;&lt;BR /&gt;-10&amp;nbsp; -5&amp;nbsp; 50&amp;nbsp; 50 100&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&amp;nbsp; 42&amp;nbsp; -1&amp;nbsp; 23&lt;BR /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; -5&amp;nbsp; -7&amp;nbsp; 44&amp;nbsp; 12&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%let howmany = 5;&lt;/P&gt;&lt;P&gt;%macro want(howmany);&lt;BR /&gt; %IF &amp;amp;howmany GT 0 %THEN&lt;BR /&gt;&amp;nbsp; %DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; data want;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do j=1 %to &amp;amp;howmany;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if var&amp;amp;j. lt 0 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&amp;amp;j.=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else var&amp;amp;j.=var&amp;amp;j.+(-15)*(var&amp;amp;j./200);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;BR /&gt;%mend want;&lt;/P&gt;&lt;P&gt;%want(5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.JPG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/7352_Capture.JPG" width="450" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 15:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136797#M36888</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2014-09-09T15:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Summing fields with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136798#M36889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 15:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-fields-with-conditions/m-p/136798#M36889</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2014-09-09T15:04:11Z</dc:date>
    </item>
  </channel>
</rss>

