<?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: Reading one date from two numeric formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460737#M117136</link>
    <description>&lt;P&gt;I think you're omitting a case here.&amp;nbsp; Couldn't January 1, 2016 be represented as 6 digits?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, taking your rule that these are actually numeric variables, I would create a character version that contains 8 digits.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if frdate &amp;gt; 10000000 then char_version = put(frdate, 8.);&lt;/P&gt;
&lt;P&gt;else if frdate &amp;gt; 1000000 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; frdate = 10 * int(frdate / 10000) + mod(frdate, 10000);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; char_version = put(frdate, 8.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else if frdate &amp;gt; 100000 then do;&amp;nbsp; /* to handle 112016 = January 1, 2016 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; frdate = 100 * int(frdate / 10000) + mod(frdate, 10000);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; char_version = put(frdate, 8.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, convert that character version to a valid SAS date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;fr_sasdate = input(put(char_version, z8.), ddmmyy8.);&lt;/P&gt;
&lt;P&gt;format fr_sasdate yymmdd10.;&amp;nbsp; /* or pick some other format that you prefer */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is untested at the moment, so I may tweak it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;***************** EDITED:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Upon review of the results of this code, there are more problems than expected.&amp;nbsp; For example, how do you know what date this is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1112016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will make the choice for you, but how will you know that SAS did the right thing?&lt;/P&gt;</description>
    <pubDate>Tue, 08 May 2018 15:59:10 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-05-08T15:59:10Z</dc:date>
    <item>
      <title>Reading one date from two numeric formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460719#M117127</link>
      <description>&lt;P&gt;I have an outpatient dataset with a variable "FRDATE" that is formatted numeric 8. Each observation has either 7 numbers (ddmyyyy) or 8 numbers (ddmmyyyy). How do I convert this numeric field to a unified date field?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex:&amp;nbsp; Patient&amp;nbsp; FRDATE&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Obs 1&amp;nbsp; &amp;nbsp; &amp;nbsp;2162016&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Obs 2&amp;nbsp; &amp;nbsp;21122016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 14:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460719#M117127</guid>
      <dc:creator>MDH_sasuser</dc:creator>
      <dc:date>2018-05-08T14:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Reading one date from two numeric formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460723#M117128</link>
      <description>&lt;P&gt;Is that first "date" supposed to be Feb 16 2016 or June 21 2016?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did the original data brought into SAS actually have leading zeros such that the first example was 02162016, which would maybe clear up the above question?&lt;/P&gt;
&lt;P&gt;If so perhaps:&lt;/P&gt;
&lt;PRE&gt;data have;
   input frdate;
   sasdate= input(put(frdate,z8.-L),anydtdte.);
   format sasdate mmddyy10.;
datalines;
2162016
 21122016
;
run;&lt;/PRE&gt;
&lt;P&gt;The line is the SASDATE= which reads in a text version of your date with a leading 0 using an "any date" informat&amp;nbsp;&amp;nbsp;(anydtdte.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 15:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460723#M117128</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-08T15:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading one date from two numeric formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460725#M117129</link>
      <description>&lt;P&gt;Hi you can try like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data date;&lt;BR /&gt;input patient$ date;&lt;BR /&gt;cards;&lt;BR /&gt;Obs_1 2162016&lt;BR /&gt;Obs_2 21122016&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data date1;&lt;BR /&gt;set date;&lt;BR /&gt;date1=input(date,8.);&lt;BR /&gt;format date1 ddmmyy10.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 15:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460725#M117129</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-05-08T15:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading one date from two numeric formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460726#M117130</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can check length of the char type var:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length temp_date $8;&lt;BR /&gt;temp_date = put(frdate, 8.);
if length(temp_date) = 7
   then tempdate = cat(substr(temp_date,1,2) , '0' ,
                                    substr(temp_date,3,5) );
frdtae = input(temp_date, ddmmyy8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 15:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460726#M117130</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-05-08T15:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading one date from two numeric formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460737#M117136</link>
      <description>&lt;P&gt;I think you're omitting a case here.&amp;nbsp; Couldn't January 1, 2016 be represented as 6 digits?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, taking your rule that these are actually numeric variables, I would create a character version that contains 8 digits.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if frdate &amp;gt; 10000000 then char_version = put(frdate, 8.);&lt;/P&gt;
&lt;P&gt;else if frdate &amp;gt; 1000000 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; frdate = 10 * int(frdate / 10000) + mod(frdate, 10000);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; char_version = put(frdate, 8.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else if frdate &amp;gt; 100000 then do;&amp;nbsp; /* to handle 112016 = January 1, 2016 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; frdate = 100 * int(frdate / 10000) + mod(frdate, 10000);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; char_version = put(frdate, 8.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, convert that character version to a valid SAS date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;fr_sasdate = input(put(char_version, z8.), ddmmyy8.);&lt;/P&gt;
&lt;P&gt;format fr_sasdate yymmdd10.;&amp;nbsp; /* or pick some other format that you prefer */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is untested at the moment, so I may tweak it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;***************** EDITED:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Upon review of the results of this code, there are more problems than expected.&amp;nbsp; For example, how do you know what date this is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1112016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will make the choice for you, but how will you know that SAS did the right thing?&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 15:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460737#M117136</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-08T15:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading one date from two numeric formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460738#M117137</link>
      <description>&lt;P&gt;Thank you all so much for the quick replies and solutions. This agency sent me 5 years to merge, each year in a a text file with a different delineation and data dictionary... my eyes are crossing&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 15:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-one-date-from-two-numeric-formats/m-p/460738#M117137</guid>
      <dc:creator>MDH_sasuser</dc:creator>
      <dc:date>2018-05-08T15:54:45Z</dc:date>
    </item>
  </channel>
</rss>

