<?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: Merge with different date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607865#M176789</link>
    <description>&lt;P&gt;Formats do not affect merge. The merge will be done using the unformatted values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, are the unformatted values the same so that the data sets can merge properly together???&lt;/P&gt;</description>
    <pubDate>Wed, 27 Nov 2019 21:12:06 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-11-27T21:12:06Z</dc:date>
    <item>
      <title>Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607861#M176787</link>
      <description>&lt;P&gt;Hi There&lt;/P&gt;&lt;P&gt;I'm trying to merge two files by "date"&amp;nbsp;&lt;/P&gt;&lt;P&gt;but "date" has different format in two files&lt;/P&gt;&lt;P&gt;the format of "date" in file T2 is&amp;nbsp;BEST12.&lt;/P&gt;&lt;P&gt;the format of "date" in file SP2 is&amp;nbsp;YYMMDDN8.&lt;/P&gt;&lt;P&gt;in this case how can I merge two files by "date"&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the code I used&lt;/P&gt;&lt;P&gt;DATA master;&lt;BR /&gt;MERGE T2 (in=a)&lt;BR /&gt;sp2 (in=b);&lt;BR /&gt;by date;&lt;BR /&gt;if A;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607861#M176787</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-27T21:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607865#M176789</link>
      <description>&lt;P&gt;Formats do not affect merge. The merge will be done using the unformatted values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, are the unformatted values the same so that the data sets can merge properly together???&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607865#M176789</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-27T21:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607869#M176790</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/124145"&gt;@Xinhui&lt;/a&gt;&amp;nbsp;, I think you'll need to get the dates into an actual date format. I suspect your date in t2 is a character of the form "2018/10/01".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t2_new;
/* set t2; */
/* date_new = input(compress(date,"/"),yymmdd8.); */
date_new = input(compress("2018/10/01","/"),yymmdd8.);
var_from_t2="Hi from T2!";
format date_new yymmddn8.;
run;

data sp2_new;
/* set sp2; */
/* date_new = input("20181001",yymmdd8.); */
date_new = input("20181001",yymmdd8.);
var_from_sp2="Hi from SP2!";
format date_new yymmddn8.;
run;

proc sort data=t2_new; by date_new; run;
proc sort data=sp2_new; by date_new; run;

data want;
merge t2_new(in=a) sp2_new(in=b);
by date_new;
if a;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot from 2019-11-27 14-48-42.png" style="width: 266px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34299i3714D9B56F9BB5C3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot from 2019-11-27 14-48-42.png" alt="Screenshot from 2019-11-27 14-48-42.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;mentioned, if both variables are SAS dates, it won't matter that they differ in display format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607869#M176790</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-27T21:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607871#M176791</link>
      <description>&lt;P&gt;Or one of the dates is a numeric like 20191210, which won't merge with dates formatted as MMDDYYN8.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607871#M176791</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-27T21:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607875#M176792</link>
      <description>&lt;P&gt;no both of "date" are present as 20180101 in the file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607875#M176792</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-27T21:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607878#M176794</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, I cleaned up my response the "numeric" was misleading!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607878#M176794</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-27T21:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607879#M176795</link>
      <description>&lt;P&gt;SAS will merge by the actual values stored in the variables, not by how you have told it to display the values.&lt;/P&gt;
&lt;P&gt;So if DATE in SP2 has today's date then the value will be 21,880 it will be displayed as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;20191127&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if DATE in&amp;nbsp; T2 also have the value 21,880 then it will be displayed as:&lt;/P&gt;
&lt;PRE&gt;       21880&lt;/PRE&gt;
&lt;P&gt;but the values will match.&lt;/P&gt;
&lt;P&gt;However if DATE in T2 has the value 20,191,127 has the it will be displayed as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    20191127&lt;/PRE&gt;
&lt;P&gt;Which looks a lot like how the 21,880 that as stored in SP2 looks, but the value is almost 1,000 times larger.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably want to convert the values in T2 into actual dates. So assuming that you have values like 20,191,127 then you can fix them by converting them to characters string, converting the string into a date value. While you are at it attach a date format so they look like dates when printed.&amp;nbsp; You probably will want to use a format like DATE9 or YYMMDD10 instead of the confusing YYMMDDN8 format that makes the displayed value look like a normal number instead of date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t2_fixed;
  set t2;
  date=input(put(date,8.).yymmdd8.);
  format date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then they will merge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master;
  merge t2_fixed (in=in1) sp2 (in=in2);
  by date;
  if in1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607879#M176795</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-27T21:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with different date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607880#M176796</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/124145"&gt;@Xinhui&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;no both of "date" are present as 20180101 in the file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;the format of "date" in file SP2 is YYMMDDN8.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These two statements are contradictory. 20180101 cannot be merged with a date value formatted as YYMMDDN8. because the unformatted dates will not match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's the case, then you have to convert 20180101 into a date that SAS recognizes, as it is not a SAS date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So ... instead of me posting code, I see that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; has already done this.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-different-date-format/m-p/607880#M176796</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-27T21:52:31Z</dc:date>
    </item>
  </channel>
</rss>

