<?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 Excluding people based on rows in a second dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237048#M43439</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets. Dataset1&amp;nbsp;is at the person-level and has ID as well as some categorical variables. Dataset2 is at the person-event level and has a matching ID variable and an event date variable that is month/year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 1&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;categ_var1...categ_var5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; abc &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ghi&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; def &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jkl&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 2&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; event_date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Apr 2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; May 2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jun 2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Aug 2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some people from Dataset 1 will not be in Dataset 2 at all. What I want is to keep everyone from Dataset 1 that has events in April, May, and June 2012 in Dataset 2 (so ID=1 would stay, ID=2 would not as they were not found in Dataset 2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Nov 2015 20:57:27 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2015-11-30T20:57:27Z</dc:date>
    <item>
      <title>Excluding people based on rows in a second dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237048#M43439</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets. Dataset1&amp;nbsp;is at the person-level and has ID as well as some categorical variables. Dataset2 is at the person-event level and has a matching ID variable and an event date variable that is month/year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 1&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;categ_var1...categ_var5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; abc &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ghi&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; def &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jkl&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 2&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; event_date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Apr 2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; May 2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jun 2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Aug 2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some people from Dataset 1 will not be in Dataset 2 at all. What I want is to keep everyone from Dataset 1 that has events in April, May, and June 2012 in Dataset 2 (so ID=1 would stay, ID=2 would not as they were not found in Dataset 2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2015 20:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237048#M43439</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2015-11-30T20:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding people based on rows in a second dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237057#M43441</link>
      <description>&lt;P&gt;Here's a way to do it using a subquery in a SQL procedure:&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;data dataset1;
input ID$ categ_var1$ categ_var2$ categ_var3$ categ_var4$ categ_var5$;
datalines;
1 abc ghi mno st wx
2 def jkl pqr uv yz
;
run;

data dataset2;
input ID$ event_date;
informat ID $3. event_date mmddyy10.;
format ID $3. event_date mmddyy10.;
datalines;
1 04/01/2012
1 05/01/2012
1 06/01/2012
1 08/01/2012
;
run;

proc sql;
create table want as
select A.*
from dataset1 as A
Where A.ID in (select distinct ID 
	       from dataset2 as B
	       Where year(B.event_date)=2012 AND month(B.event_date) in (4,5,6));
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2015 21:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237057#M43441</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-11-30T21:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding people based on rows in a second dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237096#M43452</link>
      <description>&lt;P&gt;The exact syntax will depend on whether EVENT_DATE is text vs. a SAS date. &amp;nbsp;You could use the SQL approach already suggested (but with modifications for the EVENT_DATE selection if EVENT_DATE happens to be text). &amp;nbsp;It's also straightforward to sort and merge. &amp;nbsp;Assuming both data sets are sorted by ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge dataset1 (in=in1) dataset2 (in=in2);&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if in1 and in2;&lt;/P&gt;
&lt;P&gt;/* For a text EVENT_DATE subset as follows */&lt;/P&gt;
&lt;P&gt;if event_date in ('Apr 2012', 'May 2012', 'Jun 2012');&lt;/P&gt;
&lt;P&gt;/* For a SAS date version of EVENT_DATE subset as follows */&lt;/P&gt;
&lt;P&gt;if '01apr2012'd &amp;lt;= event_date &amp;lt;= '30jun2012'd;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Things to consider: &amp;nbsp;Do you want to drop EVENT_DATE from the final data set? &amp;nbsp;Could there be variations in spelling, such as Apr, apr, and APR?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2015 03:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237096#M43452</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-12-01T03:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding people based on rows in a second dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237101#M43453</link>
      <description>&lt;P&gt;You could also use a hash table if the lookup dataset can fit into memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA WANT;
	IF _N_ = 1 THEN DO;
		DECLARE HASH H(DATASET:"WORK.DS2 (WHERE = (EVENT_DATE IN ('APRIL 2012', 'MAY 2012', 'JUNE 2012')))");
		H.DEFINEKEY("ID");
		H.DEFINEDONE();
	END;

	SET WORK.DS1;

	RC = H.CHECK();

	IF RC = 0 THEN OUTPUT;
RUN;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above example we are subsetting the lookup data by the event_dates.&amp;nbsp; This is only applicable to SAS 9.2 and above.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2015 04:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-people-based-on-rows-in-a-second-dataset/m-p/237101#M43453</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2015-12-01T04:27:19Z</dc:date>
    </item>
  </channel>
</rss>

