<?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: Working with Two Datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312208#M67680</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
  select *    
  from TRADE
  where not exists(select * 
                   from ANNOUNCE 
                   where TRADE.CUSIP = ANNOUNCE.CUSIP
                     and TRADE_DATE-1 &amp;lt;= ANNOUNCE_DATE &amp;lt;= TRADE_DATE+1 );
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2016 05:05:37 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2016-11-17T05:05:37Z</dc:date>
    <item>
      <title>Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/311850#M67513</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets which I attached: one is trade_data and another is announce_data. I need to creat a new dataset as following: if the tradedate of a cusip (i.e. firm) in the "trade_data" is within&amp;nbsp;&lt;SPAN&gt;±1 day of the announce date in the "announce_data" file, then the observation of that tradeday of that firm will have to be removed. For example, a firm has an announce date on 16 november 2004 in "announce_data". If that firm has a trade date either on 15 november 2004 or 16 november 2004 or 17 november 2004 then the observation of that trade date will have to be removed. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 21:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/311850#M67513</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-15T21:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/311856#M67516</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ANNOUNCE;
input CUSIP ANNOUNCE_DATE : ddmmyy10.;
cards;
00036110 08/01/2004
00036110 29/06/2004
00036110 22/09/2004
00036110 17/12/2004
00036110 16/03/2005
run;

data TRADE;
input TRADE_DATE ddmmyy10. YEAR CUSIP ;
cards;
05/01/2004 2004 00036110
05/01/2004 2004 00036110
06/01/2004 2004 00036110
07/01/2004 2004 00036110
23/01/2004 2004 00036110
run;

data WANT;
  set TRADE;
  if _N_=1 then do;
    dcl hash ANNOUNCE(dataset:'ANNOUNCE');
    ANNOUNCE.definekey('CUSIP','ANNOUNCE_DATE');
    ANNOUNCE.definedone();
    call missing (ANNOUNCE_DATE);
  end;
  if ANNOUNCE.check(key:CUSIP, key:TRADE_DATE-1) =0 
   | ANNOUNCE.check(key:CUSIP, key:TRADE_DATE  ) =0 
   | ANNOUNCE.check(key:CUSIP, key:TRADE_DATE+1) =0 then delete;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 21:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/311856#M67516</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-11-15T21:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/311948#M67566</link>
      <description>&lt;P&gt;Thanks a lot. I think it works. By the by, is it possible to solve by using proc sql?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 10:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/311948#M67566</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-16T10:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312186#M67669</link>
      <description>&lt;P&gt;It's written as two steps, but it's really only one pass of the data since ANN_WINDOW is a data seet VIEW, not a data set FILE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Make a data set view of trade dates that should be excluded*/
data ann_window/view=ann_window;
  set ann;
  do trade_date=announce_date-1 to announce_date+1;
    output;
  end;
run;

data want;
  merge trades ann_window (in=inw);
  by cusip trade_date;
  if inw=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2016 02:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312186#M67669</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-17T02:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312208#M67680</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
  select *    
  from TRADE
  where not exists(select * 
                   from ANNOUNCE 
                   where TRADE.CUSIP = ANNOUNCE.CUSIP
                     and TRADE_DATE-1 &amp;lt;= ANNOUNCE_DATE &amp;lt;= TRADE_DATE+1 );
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 05:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312208#M67680</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-11-17T05:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312334#M67728</link>
      <description>&lt;P&gt;Neither the PRoC SQL nor the hash solution took advantage of the sorted order of your data sets, which is why I&amp;nbsp; offered the solution using the data set view.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, a more challenging (and common problem for financial researchers) is to elminate a three-trading-windows centered on the announcment date, rather than a three calendar-day solutions.&amp;nbsp;&amp;nbsp; this wold make the sql and hash&amp;nbsp;a good deal more complicated, but the data-set-view technique holds up.&amp;nbsp; The main change below is the second SET statement in the DATA WANT step.&amp;nbsp; It has the FIRSTOBS=2 parement, used to look ahead one record, which in turn allows determination of whether the record-in-hand is one tradyiing day prior to an announcement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ta / view=ta;
  merge Trades  Announce (in=ina rename=(announce_date=trade_date));
  by cusip trade_date;
  in_a=ina;
run;

data want;
  set ta;
  by cusip;

  /* read ahead one record */
  if eof=0 then set ta (firstobs=2 keep=in_a rename=(in_a=next_in_a)) end=eof;
  else next_in_a=0;

  if in_a or
     (lag(in_a) and not(first.cusip)) or 
     (next_in_a and not(last.cusip))
  then delete;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2016 18:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312334#M67728</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-17T18:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312353#M67742</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;For the second datastep in your first reply, merging does not work since the two datasets need to be sorted at first. Since ann_window is a view table it cannot be sorted. So what can be done?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 15:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312353#M67742</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-17T15:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312354#M67743</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;SAS takes very long time if I use the proc sql. Even I needed to terminate the current process because SAS stopped working.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 15:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312354#M67743</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-17T15:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312375#M67749</link>
      <description>&lt;P&gt;Your annoncements data set is not likely to be large, so sort it before making the windows.&amp;nbsp; I assume your trades dataset is already sorted by cusip/date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 16:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312375#M67749</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-17T16:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312377#M67751</link>
      <description>&lt;P&gt;Following errors are shown for those codes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-7: Invalid option name END.&lt;/P&gt;&lt;P&gt;ERROR 6-185: Missing ')' parenthesis for data set option list.&lt;/P&gt;&lt;P&gt;ERROR 79-322: Expecting a ).&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 16:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312377#M67751</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-17T16:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312383#M67754</link>
      <description>Forgot a closing parens.  I've edited the program.Try it again.</description>
      <pubDate>Thu, 17 Nov 2016 16:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312383#M67754</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-17T16:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312390#M67759</link>
      <description>&lt;P&gt;Now it shows the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: File WORK.VTEMP.DATA does not exist.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 17:00:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312390#M67759</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-17T17:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312416#M67773</link>
      <description>&lt;P&gt;Ah well, this is what happens when I don't test against data.&amp;nbsp; I've editted my suggestion once again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for being my beta tester.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 18:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312416#M67773</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-17T18:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312427#M67776</link>
      <description>&lt;P&gt;Thanks for your continous support. Still it shows the following errors:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: BY variables are not properly sorted on data set WORK.ANNOUNCE.&lt;/P&gt;&lt;P&gt;ERROR: View WORK.TA.VIEW was terminated due to errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I can not sort the "ta" table since it's a view table.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 19:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312427#M67776</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-17T19:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312454#M67789</link>
      <description>&lt;P&gt;Yes the exists function is really slow in SAS, and it shows on large tables.&lt;/P&gt;
&lt;P&gt;Hash tables are much faster.&lt;/P&gt;
&lt;P&gt;So have your requirements changed? Is it now trading days and not calendar days?&lt;/P&gt;
&lt;P&gt;If so you need a list of tradings days, your TRADE table doesn't have it.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 20:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312454#M67789</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-11-17T20:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312456#M67791</link>
      <description>&lt;P&gt;Abu, Abu:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If TA is not sorted, then why do you think that's the case?&amp;nbsp; And how would you fix it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I leave it to you.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 20:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312456#M67791</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-17T20:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312488#M67800</link>
      <description>&lt;P&gt;A left join should be faster than exists()&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select TRADE.CUSIP, TRADE_DATE &lt;BR /&gt;&amp;nbsp; from TRADE&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ANNOUNCE &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on TRADE.CUSIP = ANNOUNCE.CUSIP&lt;BR /&gt;&amp;nbsp; group by 1, 2&lt;BR /&gt;&amp;nbsp; having&amp;nbsp; min(abs(sum(TRADE_DATE,-ANNOUNCE_DATE))) &amp;gt;1;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 23:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312488#M67800</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-11-17T23:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Two Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312535#M67811</link>
      <description>&lt;P&gt;My trade table has trading days (the variable tradedate), not calendar days. So are your codes based on calendar days? My requirement was:&amp;nbsp;if the tradedate in the Trade table is within&amp;nbsp;&lt;SPAN&gt;±1 calendar days of the announcement date in the Announce table then that traddate in the Trade table will have to removed.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 07:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Two-Datasets/m-p/312535#M67811</guid>
      <dc:creator>AbuChowdhury</dc:creator>
      <dc:date>2016-11-18T07:28:37Z</dc:date>
    </item>
  </channel>
</rss>

