<?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: returning negative values with no matching positive value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619495#M181902</link>
    <description>&lt;P&gt;its still fine...i will still need the same result i have specified from "Data Want"&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jan 2020 13:37:14 GMT</pubDate>
    <dc:creator>Solly7</dc:creator>
    <dc:date>2020-01-23T13:37:14Z</dc:date>
    <item>
      <title>returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619482#M181892</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I need help in extracting only policy numbers with negative amount(i.e -500), but with no preceding positive amount(i.e 500) transaction&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Data Have&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Data Want&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;policy_no&amp;nbsp; &amp;nbsp;amount&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;policy_no&amp;nbsp; &amp;nbsp;amount&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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; -1000&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -800&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -350&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-800&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-50&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-350&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 13:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619482#M181892</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2020-01-23T13:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619484#M181894</link>
      <description>&lt;P&gt;What if the negative value was first?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 13:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619484#M181894</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-23T13:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619495#M181902</link>
      <description>&lt;P&gt;its still fine...i will still need the same result i have specified from "Data Want"&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 13:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619495#M181902</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2020-01-23T13:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619500#M181906</link>
      <description>&lt;P&gt;Ok. Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;              
input policy_no amount;
datalines;       
1  500 
1 -500 
2 -1000
3  200 
4 -800 
5  50  
5 -50  
6 -350 
;

data want;
    if _N_=1 then do;
        dcl hash h (dataset : "have");
        h.definekey ("policy_no", "amount");
        h.definedone ();
    end;

    set have(where=(amount &amp;lt; 0));

    if h.check(key : policy_no, key : -amount);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619500#M181906</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-23T14:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619510#M181910</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Have  ;                                           
input policy_no   amount ;
cards; 
1                500                                 
1                -500                                 
2                -1000                             
3                 200
4                 -800
5                   50
5                   -50
6                   -350
;
data want;
 if _n_=1 then do;
   dcl hash H (multidata:'y') ;
   h.definekey  ("amount") ;
   h.definedata ("amount") ;
   h.definedone () ;
 end;
 do _n_=1 by 1 until(last.policy_no);
  set have;
  by policy_no;
  if amount&amp;gt;0 then h.add();
 end;
 do _n_=1 to _n_;
  set have;
  if amount&amp;gt;=0 then continue;
  if amount&amp;lt;0 and h.check(key:abs(amount))=0 then do;
   h.removedup(key:abs(amount));
   continue;
  end;
  output;
 end;
 h.clear();
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619510#M181910</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-23T14:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619514#M181913</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
    class policy_no;
    var amount;
    output out=_stats_(drop=_: where=(amount&amp;lt;0 and max&amp;lt;0)) min= max=max;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619514#M181913</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-23T14:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619526#M181919</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select policy_no, amount
	from have
	where amount &amp;lt; 0
		  and amount not in (select -(amount) from have where amount &amp;gt; 0);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619526#M181919</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-23T14:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619555#M181936</link>
      <description>&lt;P&gt;A variation that may be of interest.&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
    class policy_no;
    var amount;
    output out=_stats_(drop=_: where=(amount&amp;lt;0 )) sum=;
run;&lt;/PRE&gt;
&lt;P&gt;This would actually show policy where there is a negative value greater than the positive balances and doesn't actually use order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 15:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619555#M181936</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-01-23T15:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619561#M181938</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;A variation that may be of interest.&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
    class policy_no;
    var amount;
    output out=_stats_(drop=_: where=(amount&amp;lt;0 )) sum=;
run;&lt;/PRE&gt;
&lt;P&gt;This would actually show policy where there is a negative value greater than the positive balances and doesn't actually use order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's an interesting point. However, the original requirement was "&lt;SPAN&gt;but with no preceding positive amount(i.e 500) transaction" and so the way I interpret this, if there is a record at –500 and another record for the same policy_no at +250, this should not be in the output data set because the requirement "no preceding positive amount" is not met here. However, we would need&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296078"&gt;@Solly7&lt;/a&gt;&amp;nbsp;to clarify.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 15:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619561#M181938</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-23T15:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: returning negative values with no matching positive value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619785#M182045</link>
      <description>&lt;P&gt;Thank you..it works like magic!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 09:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/returning-negative-values-with-no-matching-positive-value/m-p/619785#M182045</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2020-01-24T09:58:13Z</dc:date>
    </item>
  </channel>
</rss>

