<?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: Merging data by ID and the nearest quarter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-ID-and-the-nearest-quarter/m-p/375212#M89927</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's impossible to reply without sample data, but one thing stands out:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;gt;&amp;nbsp;&lt;SPAN&gt;I format the date of both&amp;nbsp;dataset as yyq. (ie. year and quarter), then sort them &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;formatting has no effect on the sort or the merge, it only affects how the value is displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to merge by quarter you need to make this known. Either create a new variable, or change the SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;on &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;dataset1&lt;/SPAN&gt;&lt;SPAN&gt;.PERMNO=&lt;/SPAN&gt;&lt;SPAN&gt;dataset2&lt;/SPAN&gt;&lt;SPAN&gt;.LPERMNO &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;and put(&lt;/SPAN&gt;&lt;SPAN&gt;dataset1&lt;/SPAN&gt;&lt;SPAN&gt;.DATE,yyq.)=put(&lt;/SPAN&gt;&lt;SPAN&gt;dataset2&lt;/SPAN&gt;&lt;SPAN&gt;.DATADATE,yyq.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2017 06:40:05 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2017-07-12T06:40:05Z</dc:date>
    <item>
      <title>Merging data by ID and the nearest quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-ID-and-the-nearest-quarter/m-p/375209#M89926</link>
      <description>&lt;P&gt;Hi everyone.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two dataset&amp;nbsp;that need to be merged: The first dataset contains around 39k observations, which are acquistion activities taken by U.S firms. The dataset contains the firms' unique ID (called PERMNO), and the date on which the acquisitions were completed. I want to merge this dataset with the second dataset, which contains PERMNO and each&amp;nbsp;firm's quarterly accounting data (eg total asset) over a period of time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I format the date of both&amp;nbsp;dataset as yyq. (ie. year and quarter), then sort them by PERMNO and date. I then merge by PERMNO and date using proc sql, the code is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want&amp;nbsp;as&lt;BR /&gt;select dataset1.*,dataset2.*&lt;BR /&gt;from &lt;SPAN&gt;dataset1&lt;/SPAN&gt; left join &lt;SPAN&gt;dataset2&lt;/SPAN&gt;&lt;BR /&gt;on &lt;SPAN&gt;dataset1&lt;/SPAN&gt;.PERMNO=&lt;SPAN&gt;dataset2&lt;/SPAN&gt;.LPERMNO and &lt;SPAN&gt;dataset1&lt;/SPAN&gt;.date=&lt;SPAN&gt;dataset2&lt;/SPAN&gt;.datadate;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the merged table has a significant amount of observations missing, which should not be the case according to the two original datasets.&amp;nbsp;&amp;nbsp;Have I missed something?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 05:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-ID-and-the-nearest-quarter/m-p/375209#M89926</guid>
      <dc:creator>evvvvvvvvv</dc:creator>
      <dc:date>2017-07-12T05:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by ID and the nearest quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-ID-and-the-nearest-quarter/m-p/375212#M89927</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's impossible to reply without sample data, but one thing stands out:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;gt;&amp;nbsp;&lt;SPAN&gt;I format the date of both&amp;nbsp;dataset as yyq. (ie. year and quarter), then sort them &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;formatting has no effect on the sort or the merge, it only affects how the value is displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to merge by quarter you need to make this known. Either create a new variable, or change the SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;on &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;dataset1&lt;/SPAN&gt;&lt;SPAN&gt;.PERMNO=&lt;/SPAN&gt;&lt;SPAN&gt;dataset2&lt;/SPAN&gt;&lt;SPAN&gt;.LPERMNO &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;and put(&lt;/SPAN&gt;&lt;SPAN&gt;dataset1&lt;/SPAN&gt;&lt;SPAN&gt;.DATE,yyq.)=put(&lt;/SPAN&gt;&lt;SPAN&gt;dataset2&lt;/SPAN&gt;&lt;SPAN&gt;.DATADATE,yyq.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 06:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-ID-and-the-nearest-quarter/m-p/375212#M89927</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-12T06:40:05Z</dc:date>
    </item>
  </channel>
</rss>

