<?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: keeping observation based on two variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701347#M214759</link>
    <description>&lt;P&gt;Sorry, the output data is the following&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID    matchto  kp 	 
001 1 1 
003 3 1 
004 1 0
006 3 0&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Nov 2020 20:11:10 GMT</pubDate>
    <dc:creator>lillymaginta1</dc:creator>
    <dc:date>2020-11-24T20:11:10Z</dc:date>
    <item>
      <title>keeping observation based on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701345#M214758</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    matchto  kp ;	 
cards;
001 1 1 
002 2 0
003 3 1 
004 1 0
005 2 0
006 3 0
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the data above. I am trying to create a subset based on the following two conditions: a) either kp=1 then keep or b) if kp=0 but the matchto variable equal to another one where kp=1 then also keep. For example, keep id 004 and 006 since the value of "matchto" equal to the one where kp=1.&lt;/P&gt;&lt;P&gt;The output&amp;nbsp; data&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;001 1 1 003 3 1 004 1 0 006 3 0&lt;/CODE&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 20:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701345#M214758</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2020-11-24T20:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: keeping observation based on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701347#M214759</link>
      <description>&lt;P&gt;Sorry, the output data is the following&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID    matchto  kp 	 
001 1 1 
003 3 1 
004 1 0
006 3 0&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2020 20:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701347#M214759</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2020-11-24T20:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: keeping observation based on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701350#M214760</link>
      <description>&lt;P&gt;SQL is great here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from have
where kp=1 or matchto in (select distinct matchto from have where kp=1);
quit&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69937"&gt;@lillymaginta1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    matchto  kp ;	 
cards;
001 1 1 
002 2 0
003 3 1 
004 1 0
005 2 0
006 3 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have the data above. I am trying to create a subset based on the following two conditions: a) either kp=1 then keep or b) if kp=0 but the matchto variable equal to another one where kp=1 then also keep. For example, keep id 004 and 006 since the value of "matchto" equal to the one where kp=1.&lt;/P&gt;
&lt;P&gt;The output&amp;nbsp; data&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;001 1 1 003 3 1 004 1 0 006 3 0&lt;/CODE&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 20:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701350#M214760</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-24T20:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: keeping observation based on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701359#M214764</link>
      <description>&lt;P&gt;Elegant and super fast solution&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just adding variety to menu-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards ;
input ID    matchto  kp ;	 
cards;
001 1 1 
002 2 0
003 3 1 
004 1 0
005 2 0
006 3 0
;

data want;
 if _n_=1 then do;
  dcl hash h(dataset:'have(where=(kp))');
  h.definekey('matchto');
  h.definedone();
 end;
 set have;
 if kp or h.check()=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2020 20:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701359#M214764</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-24T20:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: keeping observation based on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701378#M214775</link>
      <description>Thank you both!</description>
      <pubDate>Tue, 24 Nov 2020 21:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-observation-based-on-two-variables/m-p/701378#M214775</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2020-11-24T21:47:40Z</dc:date>
    </item>
  </channel>
</rss>

