<?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: Find the By group with values within a limit in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314052#M313073</link>
    <description>&lt;PRE&gt;

data have;
input ID            Value;
cards;
100         1792
100         68193
100         -66173
100         1012
100         -366
101         -580
101          296
101         -37
102         13008
102         -205
102         2808
102         1185
;
run;
proc sql;
select distinct id
 from have
  group by id
   having sum(value lt -1000)=0 and sum(value between -1000 and -1) ne 0;
quit;

&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Nov 2016 10:49:19 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-11-24T10:49:19Z</dc:date>
    <item>
      <title>Find the By group with values within a limit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314041#M313070</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not able to find the ID which has negative values within the&amp;nbsp;BY group. Let me explain. My data looks like below:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1792&lt;/P&gt;&lt;P&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 68193&lt;/P&gt;&lt;P&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -66173&lt;/P&gt;&lt;P&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1012&lt;/P&gt;&lt;P&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -366&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -580&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;296&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -37&lt;/P&gt;&lt;P&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13008&lt;/P&gt;&lt;P&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -205&lt;/P&gt;&lt;P&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2808&lt;/P&gt;&lt;P&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1185&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to identify all such ID's which, having one or more negative values within the BY group, then all should be within the range -1000 to -1.&lt;/P&gt;&lt;P&gt;Here ID 100 has a value -366 but it also has -66173. So I dont want to select this. All the negative values within the BY group should be within the above limit.&lt;/P&gt;&lt;P&gt;ID 101 has two negative values -580 &amp;amp; -37 and both lie in the limit so I will select ID 101.&lt;/P&gt;&lt;P&gt;Also, for ID 102 it has only one negative value, -205. Hence I will select it as it lies in the given range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Further, I need to differentiate between the selected ID's which have one or more negative values within the limit. Count of negative values within the limit would be helpful.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 10:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314041#M313070</guid>
      <dc:creator>amanegm</dc:creator>
      <dc:date>2016-11-24T10:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Find the By group with values within a limit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314043#M313071</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=id negcount);
set have;
by id;
retain negflag largenegflag;
if first.id
then do;
  negflag = 0;
  largenegflag = 0;
  negcount = 0;
;
if -1000 &amp;lt;= value &amp;lt;= -1
then do;
  negflag = 1;
  negcount + 1;
end;
if value &amp;lt; -1000 then largenegflag = 1;
if last.id and negflag and not largenegflag then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2016 10:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314043#M313071</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-24T10:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Find the By group with values within a limit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314049#M313072</link>
      <description>&lt;PR&gt;

data have;
input ID            Value;
cards;
100         1792
100         68193
100         -66173
100         1012
100         -366
101         -580
101          296
101         -37
102         13008
102         -205
102         2808
102         1185
;
run;
proc sql;
select distinct id
 from have
  group by id
   having sum(value lt -1000)=0 and sum(value between -1000 and -1) ne 0;
quit;

&lt;/PR&gt;</description>
      <pubDate>Thu, 24 Nov 2016 10:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314049#M313072</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-24T10:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find the By group with values within a limit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314052#M313073</link>
      <description>&lt;PRE&gt;

data have;
input ID            Value;
cards;
100         1792
100         68193
100         -66173
100         1012
100         -366
101         -580
101          296
101         -37
102         13008
102         -205
102         2808
102         1185
;
run;
proc sql;
select distinct id
 from have
  group by id
   having sum(value lt -1000)=0 and sum(value between -1000 and -1) ne 0;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2016 10:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314052#M313073</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-24T10:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Find the By group with values within a limit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314474#M313074</link>
      <description>This is a good task for taking advantage of multiple datasets in a SET statememt.  The SET statement below will insure that all the negative values greater/equal to -1000 will precede all values&amp;lt; -1000, so a test of value at last.id is sufficient:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;  retain negcount 0;&lt;BR /&gt;  set have (where=(-1000&amp;lt;=value&amp;lt;0))&lt;BR /&gt;       have (where=(value&amp;lt;-1000));&lt;BR /&gt;  by ID;&lt;BR /&gt;  if first.id then negcount=0;&lt;BR /&gt;  if value&amp;gt;= -1000 then negcount+1;&lt;BR /&gt;  if last.id &amp;amp; value&amp;gt;=-1000;&lt;BR /&gt;run;</description>
      <pubDate>Sat, 26 Nov 2016 17:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-By-group-with-values-within-a-limit/m-p/314474#M313074</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-26T17:30:41Z</dc:date>
    </item>
  </channel>
</rss>

