<?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 Merging data with dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663335#M197988</link>
    <description>&lt;P&gt;Hello All,&lt;BR /&gt;&lt;BR /&gt;I am trying to merge two files on the basis of similar firm identifiers in the two files. However, the years are different in both the files. In the first file, loan transaction dates are mentioned, and in the second file data dates are given (last date of the fiscal year). So, I would like to merge two files on the basis of firm identifiers and these two dates. Loan date should match the data date (fiscal year) in the second file.&lt;BR /&gt;&lt;BR /&gt;Cusp. Loan date. Loan amount&lt;BR /&gt;10222. 12/06/2011. 300000&lt;BR /&gt;10222. 17/01/2012. 700000&lt;BR /&gt;10222. 18/03/2013. 500000&lt;/P&gt;&lt;P&gt;10333.&amp;nbsp; 05/09/2011&amp;nbsp; 60000&lt;/P&gt;&lt;P&gt;10333.&amp;nbsp; 08/10/2013&amp;nbsp; 560000&lt;/P&gt;&lt;P&gt;10333.&amp;nbsp; 18/10/2015&amp;nbsp; 40000&lt;BR /&gt;&lt;BR /&gt;Cusp. Data date. Fiscal year.&lt;BR /&gt;10222. 31/03/2011. 2010&lt;BR /&gt;10222. 31/03/2012. 2011&lt;BR /&gt;10222. 31/03/2013. 2012&lt;BR /&gt;10222. 31/03/2014. 2013&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2012&amp;nbsp; 2011&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2013&amp;nbsp; 2012&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2014&amp;nbsp; 2013&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2015&amp;nbsp; 2014&lt;BR /&gt;&lt;BR /&gt;So, the first two loan transaction amounts (for 10222) should match the second file in the same fiscal year, i.e. 2011, considering the data date. Similarly, for 10333, first loan transaction should match with the fiscal year 2011 in the second file.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jun 2020 22:50:44 GMT</pubDate>
    <dc:creator>amanjot_42</dc:creator>
    <dc:date>2020-06-18T22:50:44Z</dc:date>
    <item>
      <title>Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663335#M197988</link>
      <description>&lt;P&gt;Hello All,&lt;BR /&gt;&lt;BR /&gt;I am trying to merge two files on the basis of similar firm identifiers in the two files. However, the years are different in both the files. In the first file, loan transaction dates are mentioned, and in the second file data dates are given (last date of the fiscal year). So, I would like to merge two files on the basis of firm identifiers and these two dates. Loan date should match the data date (fiscal year) in the second file.&lt;BR /&gt;&lt;BR /&gt;Cusp. Loan date. Loan amount&lt;BR /&gt;10222. 12/06/2011. 300000&lt;BR /&gt;10222. 17/01/2012. 700000&lt;BR /&gt;10222. 18/03/2013. 500000&lt;/P&gt;&lt;P&gt;10333.&amp;nbsp; 05/09/2011&amp;nbsp; 60000&lt;/P&gt;&lt;P&gt;10333.&amp;nbsp; 08/10/2013&amp;nbsp; 560000&lt;/P&gt;&lt;P&gt;10333.&amp;nbsp; 18/10/2015&amp;nbsp; 40000&lt;BR /&gt;&lt;BR /&gt;Cusp. Data date. Fiscal year.&lt;BR /&gt;10222. 31/03/2011. 2010&lt;BR /&gt;10222. 31/03/2012. 2011&lt;BR /&gt;10222. 31/03/2013. 2012&lt;BR /&gt;10222. 31/03/2014. 2013&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2012&amp;nbsp; 2011&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2013&amp;nbsp; 2012&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2014&amp;nbsp; 2013&lt;/P&gt;&lt;P&gt;10333&amp;nbsp; 31/01/2015&amp;nbsp; 2014&lt;BR /&gt;&lt;BR /&gt;So, the first two loan transaction amounts (for 10222) should match the second file in the same fiscal year, i.e. 2011, considering the data date. Similarly, for 10333, first loan transaction should match with the fiscal year 2011 in the second file.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jun 2020 22:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663335#M197988</guid>
      <dc:creator>amanjot_42</dc:creator>
      <dc:date>2020-06-18T22:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663336#M197989</link>
      <description>&lt;P&gt;Your fiscal year starts in April it seems?&lt;BR /&gt;&lt;BR /&gt;You can use INTNX() to align a date to the beginning or end of the year and you can play around with modifying the first parameter to get the right interval to align with your fiscal year. Otherwise a basic if/then statement also works. &lt;BR /&gt;&lt;BR /&gt;Use something like this to first convert the loan_date to a 'date' and then merge on the date.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if month(loan_date) &amp;lt;=3 then fiscal_year = year(loan_date)-1; else fiscal_year = year(loan_date);

date = mdy(3, 31, fiscal_year+1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Now merge on the new calculated date in your loan table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/198822"&gt;@amanjot_42&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello All,&lt;BR /&gt;&lt;BR /&gt;I am trying to merge two files on the basis of similar firm identifiers in the two files. However, the years are different in both the files. In the first file, loan transaction dates are mentioned, and in the second file data dates are given (last date of the fiscal year). So, I would like to merge two files on the basis of firm identifiers and these two dates. Loan date should match the data date (fiscal year) in the second file.&lt;BR /&gt;&lt;BR /&gt;Cusp. Loan date. Loan amount&lt;BR /&gt;10222. 12/06/2011. 300000&lt;BR /&gt;10222. 17/01/2012. 700000&lt;BR /&gt;10222. 18/03/2013. 500000&lt;BR /&gt;&lt;BR /&gt;Cusp. Data date. Fiscal year.&lt;BR /&gt;10222. 31/03/2011. 2010&lt;BR /&gt;10222. 31/03/2012. 2011&lt;BR /&gt;10222. 31/03/2013. 2012&lt;BR /&gt;10222. 31/03/2014. 2013&lt;BR /&gt;&lt;BR /&gt;So, the first two loan transaction amounts should match the second file in the same fiscal year, i.e. 2011, considering the data date.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jun 2020 22:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663336#M197989</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-18T22:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663337#M197990</link>
      <description>&lt;DIV class="ydpf6161a5fyahoo-style-wrap"&gt;Thanks for your reply,&lt;/DIV&gt;&lt;DIV class="ydpf6161a5fyahoo-style-wrap"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ydpf6161a5fyahoo-style-wrap"&gt;One thing, I forgot to mention is that there are different firms in the sample, and not all of them are having the same data dates (I mean, 31st march as the last date of the fiscal year). Some have 30th June, some have 30th September, and some even have 31st Jan!&lt;/DIV&gt;&lt;DIV class="ydpf6161a5fyahoo-style-wrap"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ydpf6161a5fyahoo-style-wrap"&gt;Regards,&lt;/DIV&gt;&lt;DIV class="ydpf6161a5fyahoo-style-wrap"&gt;Aman&lt;/DIV&gt;</description>
      <pubDate>Thu, 18 Jun 2020 22:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663337#M197990</guid>
      <dc:creator>amanjot_42</dc:creator>
      <dc:date>2020-06-18T22:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663339#M197991</link>
      <description>You definitely did not mention that and your example does not support that. Please expand your example to incorporate your additional requirements. Preferably as a data step. &lt;BR /&gt;</description>
      <pubDate>Thu, 18 Jun 2020 22:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663339#M197991</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-18T22:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663340#M197992</link>
      <description>&lt;P&gt;Sorry about that!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please have a look at the example now!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jun 2020 22:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663340#M197992</guid>
      <dc:creator>amanjot_42</dc:creator>
      <dc:date>2020-06-18T22:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663342#M197993</link>
      <description>&lt;P&gt;1. Build a format based on your fiscal date begin and end i.e. begin and end marking a fiscal period&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1Apr2011 - 31Mar2012 = 31Mar2012&lt;/P&gt;
&lt;P&gt;2. Apply your format to your first dataset.&lt;/P&gt;
&lt;P&gt;3. after doing that join it with the second dataset.&lt;/P&gt;
&lt;P&gt;4. If there are overlapping ranges then it will be a problem&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Idea 2: Work backwards&lt;/P&gt;
&lt;P&gt;1. On dataset build the start of fiscal year for each row.&lt;/P&gt;
&lt;P&gt;2. do a sql join based on your id and date from dataset 1 falls between start and end dates of fiscal year in dataset 2&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jun 2020 22:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663342#M197993</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-18T22:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663344#M197995</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_1;
informat loan_date ddmmyy10.;
format loan_date ddmmyy10.;
input cusp loan_date loan_amount;
cards;
10222 12/06/2011 300000
10222 17/01/2012 700000
10222 18/03/2013 500000
10333 05/09/2011 60000
10333 08/10/2013 560000
10333 18/10/2015 40000
;;;
data table2;
informat fy_end_date ddmmyy10.;
format fy_end_date fy_beg_date ddmmyy10.;
input cusp fy_end_date Fyear;
fy_beg_date = intnx('year',fy_end_date,-1,'same');
cards;
10222 31/03/2011 2010
10222 31/03/2012 2011
10222 31/03/2013 2012
10222 31/03/2014 2013
10333 31/01/2012 2011
10333 31/01/2013 2012
10333 31/01/2014 2013
10333 31/01/2015 2014
;;;
run;

proc sql;
create table table3 as
select a.*,b.Fyear,b.fy_end_date from
table_1 a,
table2 b
where a.cusp = b.cusp
and a.loan_date &amp;gt; b.fy_beg_date 
and a.loan_date &amp;lt;= b.fy_end_date
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Jun 2020 23:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/663344#M197995</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-18T23:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/664042#M198335</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;It worked perfectly!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2020 18:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-with-dates/m-p/664042#M198335</guid>
      <dc:creator>amanjot_42</dc:creator>
      <dc:date>2020-06-22T18:09:41Z</dc:date>
    </item>
  </channel>
</rss>

