<?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: Need help on sql: meger two databases  for a special case in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104456#M29178</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You said that the table with daily stock returns is huge so it's may be better to touch this table as little as possible. Under the assumption that there is only 1 downgrade per firm in a 7 days window below code should work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data work.table1_extended;&lt;BR /&gt;&amp;nbsp; set work.table1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do date=rating_date-3 to rating_date+3;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql feedback;&lt;BR /&gt;&amp;nbsp; create table want as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.rating_date format=date9.,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.lpermno&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.date format=date9.,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.ret&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp; table1_extended a&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left outer join table2 b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.lpermno = b.lpermno and a.date=b.date&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by a.lpermno,a.rating_date, a.date;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 10 Feb 2013 01:48:02 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2013-02-10T01:48:02Z</dc:date>
    <item>
      <title>Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104451#M29173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, guys&lt;/P&gt;&lt;P&gt;I need your help again. I am trying to merge two database.One includes firms with bond downgradings, firm id and the date when they got downgraded. The other is a huge database with all North American firms' daily stock return .&amp;nbsp; I would like to add stock returns during a 7-day window( 3 trading days before and 3 trading days after the date of&amp;nbsp; the downgrade) for these downgraded firms to&amp;nbsp; table1 . Basicly, each observation on table1 will become 7 observatios.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I only need the date of downgrade, I can use sql merger like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table merged as select a.*, b.* from table1 as a left join table2 as b on a.lpermno=b.lpermno and a.rating_date=b.date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Above procedures will only include one date. Also,&amp;nbsp; date on table2 is&amp;nbsp; not canlendar day, there may be missing dates due to the close of stock market on weekend or holiday so it is possible that the date of downgrading might occur on the date when the market was not traded (that is, a date is not on table 2, but in table 1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attached two tables. My actual table2&amp;nbsp; is as large as 2GB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2013 23:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104451#M29173</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-09T23:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104452#M29174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming that the dates are SAS dates (and not datetimes), you only need to replace&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;and a.rating_date=b.date&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;and b.date between a.rating_date-3 and a.rating_date+3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2013 23:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104452#M29174</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-02-09T23:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104453#M29175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PG Stats,&lt;/P&gt;&lt;P&gt;Thank you . But table2's dates are not continuous,many dates are missing on table2. How can I make sure I can generate 7 dates for each observation on table1?&lt;/P&gt;&lt;P&gt;I tried , most observations only generate 4 or five dates not 7 dates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2013 23:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104453#M29175</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-09T23:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104454#M29176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will need some kind of post processing to fix up your time series. Question is: What are the rules? What value should variable RET get for dates you need to make up?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 01:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104454#M29176</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-02-10T01:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104455#M29177</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I am thinking&amp;nbsp; of adding those missing dates first then asigning a missing value to the added date for RET. Anyone easy way to do it?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 01:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104455#M29177</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-10T01:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104456#M29178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You said that the table with daily stock returns is huge so it's may be better to touch this table as little as possible. Under the assumption that there is only 1 downgrade per firm in a 7 days window below code should work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data work.table1_extended;&lt;BR /&gt;&amp;nbsp; set work.table1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do date=rating_date-3 to rating_date+3;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql feedback;&lt;BR /&gt;&amp;nbsp; create table want as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.rating_date format=date9.,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.lpermno&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.date format=date9.,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.ret&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp; table1_extended a&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left outer join table2 b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.lpermno = b.lpermno and a.date=b.date&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by a.lpermno,a.rating_date, a.date;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 01:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104456#M29178</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-02-10T01:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104457#M29179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;Thank you very mcuh. Unfortunately it is very normal in my data that one firm has multiple downgrades. What changes should I make to your code to facilitate this situation?&lt;/P&gt;&lt;P&gt;Very much appreciate your time.&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 02:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104457#M29179</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-10T02:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104458#M29180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick's code will work even if there are multiple close downgrades. You will simply get the same daily stock return associated with many downgrades. - PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 02:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104458#M29180</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-02-10T02:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on sql: meger two databases  for a special case</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104459#M29181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick and PGStats,&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 02:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-on-sql-meger-two-databases-for-a-special-case/m-p/104459#M29181</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-10T02:58:31Z</dc:date>
    </item>
  </channel>
</rss>

