<?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: Remove lines from a file based on in-between period on another file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286881#M58937</link>
    <description>Thanks! this works nicely as well. Just learned a new function!</description>
    <pubDate>Mon, 25 Jul 2016 14:44:55 GMT</pubDate>
    <dc:creator>chlorium</dc:creator>
    <dc:date>2016-07-25T14:44:55Z</dc:date>
    <item>
      <title>Remove lines from a file based on in-between period on another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286476#M58756</link>
      <description>&lt;P&gt;I have the following two datasets.&lt;/P&gt;&lt;P&gt;I want to delete the lines from A with dates that falls&amp;nbsp;within the in-out period in file B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;File A&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;SEQ	ID	date	var1
1	A12	03JAN04	242
2	A12	01FEB06	356
3	A12	06JAN08	325
4	A12	28DEC09	123
5	B34	06MAY03	985
6	B34	13JUN03	198
7	B34	10MAY05	241
8	C56	09NOV10	155
9	C56	19OCT13	352&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;File B&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;ID	date_in	date_out
A12	01JAN04	04JAN04
A12	05FEB08	08FEB08
B34	03MAY03	06MAY03
B34	09MAY05	19MAY05
C56	12JUL12	18JUL12&lt;/PRE&gt;&lt;P&gt;For example, for ID=A12, his first obs falls within 01JAN04-04JAN04, thus I delete that obs, but keep the rest.&lt;/P&gt;&lt;P&gt;Essentially, I should get the following results&lt;/P&gt;&lt;PRE&gt;SEQ	ID	date	var1
2	A12	01FEB06	356
3	A12	06JAN08	325
4	A12	28DEC09	123
6	B34	13JUN03	198
8	C56	09NOV10	155
9	C56	19OCT13	352&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both file A and B has multiple records per ID, and the between in-out period in file B is not alway constant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have a lot experience with data manipulation in SAS, I'm really clueless about&amp;nbsp;where to start,&amp;nbsp;eg. should I write a macro that loops through both file some how? or use SQL somehow?&lt;/P&gt;&lt;P&gt;I would greatly appreciate some advice on how to approach this problem.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2016 20:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286476#M58756</guid>
      <dc:creator>chlorium</dc:creator>
      <dc:date>2016-07-22T20:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Remove lines from a file based on in-between period on another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286513#M58780</link>
      <description>&lt;P&gt;The first question to answer is what is in your DATE variables? &amp;nbsp;Are they character strings, or are they SAS dates (numeric, with a date7 format)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC CONTENTS will reveal that.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2016 23:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286513#M58780</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-22T23:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Remove lines from a file based on in-between period on another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286547#M58788</link>
      <description>&lt;PRE&gt;

data A;
infile cards expandtabs truncover;
input SEQ	ID $	date : date9.	var1;
format date date9.;
cards;
1	A12	03JAN04	242
2	A12	01FEB06	356
3	A12	06JAN08	325
4	A12	28DEC09	123
5	B34	06MAY03	985
6	B34	13JUN03	198
7	B34	10MAY05	241
8	C56	09NOV10	155
9	C56	19OCT13	352
;
run;
data B;
infile cards expandtabs truncover;
input ID $	(date_in	date_out) ( : date9.);
format date_in	date_out date9.;
cards;
A12	01JAN04	04JAN04
A12	05FEB08	08FEB08
B34	03MAY03	06MAY03
B34	09MAY05	19MAY05
C56	12JUL12	18JUL12
;
run;
data key;
 set B;
 do date=date_in to date_out;
  output;
 end;
 keep id date;
run;
data want;
 if _n_=1 then do;
  if 0 then set key;
  declare hash h(dataset:'key');
  h.definekey('id','date');
  h.definedone();
 end;
set A;
if h.check()=0 then delete;
run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Jul 2016 06:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286547#M58788</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-23T06:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Remove lines from a file based on in-between period on another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286557#M58792</link>
      <description>&lt;P&gt;Here an approach using SQL&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* option 1: Delete records if target is a database table */
proc sql;
  delete from A
  where exists
    (select * from B where a.id=b.id and a.date between b.date_in and b.date_out)
  ;
quit;

/* option 2: create a new table if target is a SAS file */
proc sql;
  create table want as
  select * from a
  where not exists
    (select * from B where a.id=b.id and a.date between b.date_in and b.date_out)
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Jul 2016 08:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286557#M58792</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-07-23T08:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Remove lines from a file based on in-between period on another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286879#M58936</link>
      <description>Wow never knew sql has a "between" that solves everything easily! Thanks!</description>
      <pubDate>Mon, 25 Jul 2016 14:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286879#M58936</guid>
      <dc:creator>chlorium</dc:creator>
      <dc:date>2016-07-25T14:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Remove lines from a file based on in-between period on another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286881#M58937</link>
      <description>Thanks! this works nicely as well. Just learned a new function!</description>
      <pubDate>Mon, 25 Jul 2016 14:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-lines-from-a-file-based-on-in-between-period-on-another/m-p/286881#M58937</guid>
      <dc:creator>chlorium</dc:creator>
      <dc:date>2016-07-25T14:44:55Z</dc:date>
    </item>
  </channel>
</rss>

