<?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: Filter out dataset using month and year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618308#M181376</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp; for clarifying. Please ignore the INNER JOIN and stick to the LEFT JOIN, the 1st one. I'm glad my initial thought was right. Have a good one!&lt;/P&gt;</description>
    <pubDate>Sun, 19 Jan 2020 01:37:29 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-19T01:37:29Z</dc:date>
    <item>
      <title>Filter out dataset using month and year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618294#M181366</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I have two datasets with transaction data. I want to select the transactions present in first dataset but not in the second one by month and year.&lt;BR /&gt;&lt;BR /&gt;Dataset1:&lt;BR /&gt;&lt;BR /&gt;acct_id date&lt;BR /&gt;1234 12dec2019&lt;BR /&gt;2345 12dec2019&lt;BR /&gt;3456 12dec2019&lt;BR /&gt;4467 12dec2019&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;dataset2:&lt;BR /&gt;&lt;BR /&gt;Acct_id date&lt;BR /&gt;1234 01dec2019&lt;BR /&gt;2345 01dec2019&lt;BR /&gt;3456 21nov2019&lt;BR /&gt;4467 21nov2019&lt;BR /&gt;&lt;BR /&gt;In the above datasets I want to remove acct ids 1234 and 2345 from dataset1 (and create a new dataset) since they are already present in dataset2 to for the same month and year. But want to keep 3456 and 4467 from dataset1 since they were for the month of November in dataset 2. There are number of other variables in both dataset but I want to compare the accounts and month year only and create a new dataset from dataset1 based on dataset 2.&lt;BR /&gt;&lt;BR /&gt;What is the best way to achieve that ? Any suggestion is highly appreciated .&lt;BR /&gt;&lt;BR /&gt;Thanks!!</description>
      <pubDate>Sat, 18 Jan 2020 23:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618294#M181366</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-01-18T23:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out dataset using month and year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618296#M181368</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp; It's fun in Proc SQL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input acct_id date :date9.;
format date date9.;
cards;
1234 12dec2019
2345 12dec2019
3456 12dec2019
4467 12dec2019
;


data two;
input acct_id date :date9.;
format date date9.;
cards;
1234 01dec2019
2345 01dec2019
3456 21nov2019
4467 21nov2019
;
proc sql;
create table want as
select a.*
from one a left join two b
on a.acct_id=b.acct_id and put(a.date,monyy7. -l)=put(b.date,monyy7. -l)
where put(a.date,monyy7. -l) ne put(b.date,monyy7. -l);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Actually better with INNER JOIN. Oops So sorry&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.*
from one a inner join two b
on a.acct_id=b.acct_id and put(a.date,monyy7. -l) ne put(b.date,monyy7. -l);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Jan 2020 23:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618296#M181368</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-18T23:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out dataset using month and year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618297#M181369</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want ;
 if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("acct_id","d") ;
   h.definedone () ;
   do until(z);
    set two end=z;
	d=put(date,monyy7. -l);
	h.ref();
   end;
 end;
 set one;
 if h.check(key:acct_id,key:put(date,monyy7. -l)) ne 0;
 drop d;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Jan 2020 23:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618297#M181369</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-18T23:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out dataset using month and year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618304#M181373</link>
      <description>@nonivosrin This is perfect. But I want to include the accounts from dataset 1 which is not present in the dataset2 for the month. Will the inner join stilll work if it is present in dataset1 but not in dataset2 but want to include in the table want ?</description>
      <pubDate>Sun, 19 Jan 2020 01:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618304#M181373</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-01-19T01:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out dataset using month and year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618305#M181374</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; This is perfect. But I want to include the accounts from dataset 1 which is not present in the dataset2 for the month. Will the inner join stilll work if it is present in dataset1 but not in dataset2 but want to include in the table want ?</description>
      <pubDate>Sun, 19 Jan 2020 01:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618305#M181374</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-01-19T01:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out dataset using month and year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618307#M181375</link>
      <description>&lt;P&gt;Assuming ONE and TWO are sorted by ID/DATE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input acct_id date :date9.;
format date date9.;
cards;
1234 12dec2019
2345 12dec2019
3456 12dec2019
4467 12dec2019
;


data two;
input acct_id date :date9.;
format date date9.;
cards;
1234 01dec2019
2345 01dec2019
3456 21nov2019
4467 21nov2019
;


data want;
  set two (in=in2) one ;
  by acct_id;

  array _cal {2015:2020,12} _temporary_;
  if first.acct_id then call missing(of _cal{*});
  if in2 then _cal{year(date),month(date)}=1;
  else if _cal{year(date),month(date)}^=1 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;Just make sure the _CAL matrix has upper and lower bounds to cover the time span in your data set.&lt;/LI&gt;
&lt;LI&gt;The program reads all the cases for a given ID in data set TWO, and sets the matrix accordingly.&amp;nbsp; Then it reads all the cases for the same ID in data set ONE, and examines the matrix to determine whether to output.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sun, 19 Jan 2020 01:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618307#M181375</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-19T01:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out dataset using month and year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618308#M181376</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp; for clarifying. Please ignore the INNER JOIN and stick to the LEFT JOIN, the 1st one. I'm glad my initial thought was right. Have a good one!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 01:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-dataset-using-month-and-year/m-p/618308#M181376</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-19T01:37:29Z</dc:date>
    </item>
  </channel>
</rss>

