<?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: Output both members of group if one or other meets criteria in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505500#M32280</link>
    <description>&lt;P&gt;Create a lookup table, and merge that back:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input id $ value ;
   datalines;
1 0
2 1
2 0
3 0
3 10
4 11
4 15
5 0
5 0
;
run;

data lookup (keep=id);
set have;
by id;
retain flag;
if first.id then flag = 0;
if value then flag = 1;
if last.id and flag then output;
run;

data want1 want2;
merge
  have (in=a)
  lookup (in=b)
;
by id;
if b
then output want1;
else output want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Oct 2018 11:55:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-18T11:55:04Z</dc:date>
    <item>
      <title>Output both members of group if one or other meets criteria</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505494#M32278</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of ids and numeric values. I would like to output two datasets. The first is any id's where either id number has a value greater than zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second is a dataset where either id is only 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See below for example;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input id $ value ;
   datalines;
1 0
2 1
2 0
3 0
3 10
4 11
4 15
5 0
5 0
;run;

data want_1;
   input id $ value ;
   datalines;
2 1
2 0
3 0
3 10
4 11
4 15
;run;

data want_2;
   input id $ value ;
   datalines;
1 0
5 0
5 0
;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 11:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505494#M32278</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2018-10-18T11:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Output both members of group if one or other meets criteria</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505497#M32279</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want_1 as
   select * from have 
   group by id
   having sum(value)&amp;gt;0;
quit;

proc sql;
   create table want_2 as
   select * from have 
   group by id
   having sum(value)=0;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 11:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505497#M32279</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-18T11:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Output both members of group if one or other meets criteria</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505500#M32280</link>
      <description>&lt;P&gt;Create a lookup table, and merge that back:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input id $ value ;
   datalines;
1 0
2 1
2 0
3 0
3 10
4 11
4 15
5 0
5 0
;
run;

data lookup (keep=id);
set have;
by id;
retain flag;
if first.id then flag = 0;
if value then flag = 1;
if last.id and flag then output;
run;

data want1 want2;
merge
  have (in=a)
  lookup (in=b)
;
by id;
if b
then output want1;
else output want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 11:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505500#M32280</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-18T11:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Output both members of group if one or other meets criteria</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505524#M32283</link>
      <description>&lt;P&gt;I'm just wondering how would I amend the having part of this sql query if I wanted to output if either value had a string called 'YES'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table previous_LPT_return as
   select * from Stage_2_LPT 
   group by id_document
   having value='YES';
quit;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The above example I've posted seems to only omit all the yes strings&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 13:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505524#M32283</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2018-10-18T13:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Output both members of group if one or other meets criteria</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505527#M32284</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table previous_LPT_return as
select *
from Stage_2_LPT
where id_document in (
  select distinct id_document
  from Stage_2_LPT
  where value = 'YES'
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or you change one line in my previous code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if value = 'YES' then flag = 1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 13:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Output-both-members-of-group-if-one-or-other-meets-criteria/m-p/505527#M32284</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-18T13:26:21Z</dc:date>
    </item>
  </channel>
</rss>

