<?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: SAS left join datasets with different date formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578324#M164000</link>
    <description>&lt;P&gt;Didn't we already discuss this and propose a solution in your earlier threat at: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Matching-dates/m-p/576652#M163255" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Matching-dates/m-p/576652#M163255&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, we did. The answer there works here. Convert the date variable in each data set to an actual SAS date value containing the 1st of each month, and then merge.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Aug 2019 10:39:33 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-08-01T10:39:33Z</dc:date>
    <item>
      <title>SAS left join datasets with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578319#M163996</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to left join two datasets onto another dataset (so three datasets in total) but each dataset has a different date format - can someone please tell me the best way to match them together (I have written &lt;FONT color="#FF0000"&gt;code below but need to fill in the code highlighted in red&lt;/FONT&gt; to match the three datasets)? For the cohort_mth variable, which has a DATE9 format, this would be matched based on month e.g. any date in a month such as 01JAN2019 or 22JAN2019 would be recognised as JAN2019, so that it could be matched to JAN2019 (mth_end variable) and 201901 (obs_month variable)? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ar.dataset1&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Month end.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31456i7C254320410C5156/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Month end.PNG" alt="Month end.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ar.dataset2&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Cohort month.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31457i9CF2D49E5C3A8E61/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cohort month.JPG" alt="Cohort month.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ar.dataset3&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Observation month.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31458i85BC0D5C052426A3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Observation month.PNG" alt="Observation month.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Code so far:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;create table as&lt;BR /&gt;&amp;nbsp; &amp;nbsp;select a.mth_end,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a.account_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b.letter,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.score&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;from ar.dataset1 as a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;left join ar.dataset2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;left join ar.dataset2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#FF0000"&gt; on .....................................&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/*What code to combine the three datasets by month/year?*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;group by&amp;nbsp;mth_end,&amp;nbsp;account_id,&amp;nbsp;letter, score;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 10:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578319#M163996</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-08-01T10:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS left join datasets with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578324#M164000</link>
      <description>&lt;P&gt;Didn't we already discuss this and propose a solution in your earlier threat at: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Matching-dates/m-p/576652#M163255" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Matching-dates/m-p/576652#M163255&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, we did. The answer there works here. Convert the date variable in each data set to an actual SAS date value containing the 1st of each month, and then merge.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 10:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578324#M164000</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-01T10:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS left join datasets with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578327#M164003</link>
      <description>&lt;P&gt;Would the code be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;create table as&lt;BR /&gt;&amp;nbsp; &amp;nbsp;select a.mth_end,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a.account_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b.letter,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.score&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;from ar.dataset1 as a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;left join ar.dataset2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;left join ar.dataset2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#FF0000"&gt; &amp;nbsp;on intnx('month',a.mth_end,0,'b') = intnx('month',b.cohort_mth,0,'b') AND intnx('month',a.mth_end,0,'b') = intnx('month',c.obs_month,0,'b')&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;group by&amp;nbsp;mth_end,&amp;nbsp;account_id,&amp;nbsp;letter, score;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 10:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578327#M164003</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-08-01T10:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS left join datasets with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578353#M164016</link>
      <description>&lt;P&gt;Any time you want to match dates, they must be SAS date values, which are integers, for example today (August 1, 2019) is 21762, this is the number of days since January 1, 1960. (That's how SAS does things). So you would have to convert the dataset3 variable to an actual SAS date value. 201801 is not a SAS date value (this is done via the INPUT function, using the proper informat which is YYMMN6.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

   create table as
   select a.mth_end,
             a.account_id,
             b.letter,
             c.score
   from ar.dataset1 as a
   left join ar.dataset2 as b 
    on intnx('month',a.mth_end,0,'b') = intnx('month',b.cohort_mth,0,'b')
    left join ar.dataset3 as c
    on intnx('month',a.mth_end,0,'b') = input(c.obs_month,yymmn6.)
   group by mth_end, account_id, letter, score;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 12:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-left-join-datasets-with-different-date-formats/m-p/578353#M164016</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-01T12:16:32Z</dc:date>
    </item>
  </channel>
</rss>

