<?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: Converting dates in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898046#M43815</link>
    <description>&lt;P&gt;Both files conbtain incorrect formats for SAS dates.&amp;nbsp; So I wouldn't show you have to convert from one incorrect format to a different incorrect format.&amp;nbsp; But I will show you how to convert both files so they hold valid SAS dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first file, converting from character "dates":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_file_1;
   set file1;
   correct_dob1 = input(dob1 mmddyy10.);
   correct_dob2 = input(dob2, mmddyy10.);
   drop dob1 dob2;
   format correct_dob1 correct_dob2 mmddyy10.;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the second file, converting from numeric "dates":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data correct_file2;
   set file2;
   correct_dob1 = input(put(dob1, z8.), yymmdd8.);
   correct_dob2 = input(put(dob2, z8.), yymmdd8.);
   drop dob1 dob2;
   format correct_dob1 correct_dob2 mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There's a ton of information within the SAS documentation about how to store SAS dates.&amp;nbsp; Here's a starting point:&amp;nbsp;&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/lrcon/9.4/p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2023 00:42:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2023-10-11T00:42:08Z</dc:date>
    <item>
      <title>Converting dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898043#M43814</link>
      <description>&lt;P&gt;file 1&amp;nbsp; dob1 and dob2&amp;nbsp; look like:&lt;BR /&gt;5/13/1980&amp;nbsp; 7/3/1970&lt;BR /&gt;and it is character&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;file 2&amp;nbsp;dob1 and dob2 look like:&lt;BR /&gt;19590920&amp;nbsp; 19700813&lt;BR /&gt;and it is numeric&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do i convert file 2&lt;SPAN&gt;&amp;nbsp; dates to match file 1 dates' format?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 22:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898043#M43814</guid>
      <dc:creator>bhca60</dc:creator>
      <dc:date>2023-10-10T22:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Converting dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898046#M43815</link>
      <description>&lt;P&gt;Both files conbtain incorrect formats for SAS dates.&amp;nbsp; So I wouldn't show you have to convert from one incorrect format to a different incorrect format.&amp;nbsp; But I will show you how to convert both files so they hold valid SAS dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first file, converting from character "dates":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_file_1;
   set file1;
   correct_dob1 = input(dob1 mmddyy10.);
   correct_dob2 = input(dob2, mmddyy10.);
   drop dob1 dob2;
   format correct_dob1 correct_dob2 mmddyy10.;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the second file, converting from numeric "dates":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data correct_file2;
   set file2;
   correct_dob1 = input(put(dob1, z8.), yymmdd8.);
   correct_dob2 = input(put(dob2, z8.), yymmdd8.);
   drop dob1 dob2;
   format correct_dob1 correct_dob2 mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There's a ton of information within the SAS documentation about how to store SAS dates.&amp;nbsp; Here's a starting point:&amp;nbsp;&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/lrcon/9.4/p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 00:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898046#M43815</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-11T00:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898170#M43818</link>
      <description>I’ve tried this (the second code) and I get a warning message :&lt;BR /&gt;&lt;BR /&gt;NOTE: Invalid argument to function INPUT at line 34 column 16.&lt;BR /&gt;Warning: limit set by ERRORS= option reached. Further errors of this type will not be printed. &lt;BR /&gt;&lt;BR /&gt;I tried putting ?? DOB1  in the input statement but still get the error.</description>
      <pubDate>Wed, 11 Oct 2023 15:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898170#M43818</guid>
      <dc:creator>bhca60</dc:creator>
      <dc:date>2023-10-11T15:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Converting dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898172#M43819</link>
      <description>Full log is helpful as we can see Line 34 and which code is blanked out.</description>
      <pubDate>Wed, 11 Oct 2023 16:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898172#M43819</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-10-11T16:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Converting dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898175#M43820</link>
      <description>&lt;P&gt;Please show us the full log (as requested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;) and also PROC CONTENTS output on these two data sets.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 16:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898175#M43820</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-11T16:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Converting dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898242#M43821</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290946"&gt;@bhca60&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The requests you have received are all the right questions.&amp;nbsp; Don't just tell us what happened, show us.&amp;nbsp; These are all excellent programmers.&amp;nbsp; If any of them encountered the messages you have received, they would all debug using the same tools:&amp;nbsp; the log (including not just the error message, but the line of code that generated the message) and a PROC CONTENTS of the underlying data.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2023 02:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898242#M43821</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-12T02:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Converting dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898243#M43822</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;file 1&amp;nbsp; dob1 and dob2&amp;nbsp; look like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5/13/1980&amp;nbsp; 7/3/1970&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and it is character&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Assuming you meant that you have a SAS dataset, say it is named HAVE1, with two characters variables named DOB1 and DOB2 with strings like '5/13/1980' and '7/3/1970':&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then you can create new variables that have actual DATE values by using the INPUT() function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1_fixed;
  set have1;
  date1 = input(left(dob1),mmddyy10.);
  date2 = input(left(dob2),mmddyy10.);
  format date1 date2 date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The second one is harder:&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;file 2&amp;nbsp;dob1 and dob2 look like:&lt;BR /&gt;19590920&amp;nbsp; 19700813&lt;BR /&gt;and it is numeric&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Because you do not say what FORMAT (if any) is attached to those two variables.&amp;nbsp; If it has the format YYMMDDN8 attached then the values are already DATES and no conversion is needed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But if there is no format attach or perhaps the format 8.&amp;nbsp; or BEST12. is attached then the variables do NOT have date values.&amp;nbsp; Instead they just have numbers like&amp;nbsp;19,590,920&amp;nbsp; and 19,700,813 that only look to humans like they might be dates if you print them without the thousands separators.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To fix those you will need to first convert the numbers into strings so you can again use the INPUT() function, only this time with the YYMMDD informat.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2_fixed;
  set have2;
  date1 = input(put(dob1,Z8.),yymmdd10.);
  date2 = input(put(dob2,Z8.),yymmdd10.);
  format date1 date2 date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Not if you want to combine them you will have to drop (or rename) one or both pairs of original variables since DOB1 cannot be both a character string and a numeric variable at the same time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have1_fixed(rename=(dob1=dob1_char dob2=dob2_char))
      have2_fixed
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2023 03:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-dates/m-p/898243#M43822</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-12T03:04:44Z</dc:date>
    </item>
  </channel>
</rss>

