<?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 non-homogenous dates to SAS dates in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391020#M66203</link>
    <description>&lt;P&gt;This code I found much more accurate:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; work.want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set work.have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format datenew date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datenew =input(datehave,8.)-21916;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if missing(datenew ) then datenew =input(datehave,anydtdte10.);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Aug 2017 21:19:38 GMT</pubDate>
    <dc:creator>camfarrell25</dc:creator>
    <dc:date>2017-08-25T21:19:38Z</dc:date>
    <item>
      <title>Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390941#M66187</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to convert a variable that contains multiple format (LASTPAY)&amp;nbsp;to a single/ standardized format (NEWEXPDATE).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how one would go about that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;CF&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-inline" image-alt="sasquestion.JPG" style="width: 450px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14651i6E47370794D60F51/image-size/large?v=v2&amp;amp;px=999" role="button" title="sasquestion.JPG" alt="sasquestion.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 19:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390941#M66187</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-08-25T19:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390955#M66189</link>
      <description>&lt;P&gt;How many variations of the date do you have? I see just two in your example. But you can conditionally convert using the approprirate format based on a pattern match. That is, if it looks like it's already a SAS date value, just input(lastpay, best.). If it's a date format, input(lastpay, mmddyy10.), for example.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 15:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390955#M66189</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-08-25T15:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390961#M66190</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input lastpay$10.;
newexpdate=input(lastpay,mmddyy10.);
format newexpdate mmddyy10.;
cards;
42917
6/27/2017
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 15:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390961#M66190</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-08-25T15:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390962#M66191</link>
      <description>&lt;P&gt;Are the values you've shown correct, ie the is the correct new variable in that data set?&lt;/P&gt;
&lt;P&gt;Can you provide data as text to test?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 15:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390962#M66191</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-25T15:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390974#M66193</link>
      <description>&lt;P&gt;Most of your "dates" look like the Excel days from their offset date of 1 Jan 1900 except for a few that were entered as text in a manner that Excel did not convert to its internal date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way: Make sure that the entire column in the Excel sheet has the cell format set to a date.&lt;/P&gt;
&lt;P&gt;Then export to CSV and import into SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 16:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/390974#M66193</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-25T16:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391000#M66196</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;There is four (the data wasn't assembled by me and it the process of aggregating the dataset, the conversion wasn't done at the source unfortunately):&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;42916&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;6/23/2017&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;20170630&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;2017-06-21&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached a sample.&lt;/P&gt;&lt;P&gt;Let me know!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 19:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391000#M66196</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-08-25T19:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391001#M66197</link>
      <description>&lt;P&gt;I've attached a sample, there are at least 4 different formats (that I could find).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 19:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391001#M66197</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-08-25T19:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391005#M66198</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;data have;
  input havedate $10.;
  cards;
42916
6/23/2017
20170630
2017-06-21
;

data want;
  set have;
  format wantdate date9.;
  wantdate=input(havedate,anydtdte10.);
  if missing(wantdate) then wantdate=input(havedate,8.)-21916;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 19:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391005#M66198</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-25T19:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391009#M66199</link>
      <description>&lt;P&gt;There is another complication in your example data:&lt;/P&gt;
&lt;P&gt;You are showing a Lastpay value of 42909 that, depending on the row, apparently is supposed to transform to 09/01/2020, 11/22/2019, 05/01/2021. Is that actually the case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Against my better judgement I opened that Excel file.&lt;/P&gt;
&lt;P&gt;I copied the data column to another column to manipulate in Excel. Highlight the new column, go to the data tab, select the Text to columns and convert everything to numeric. Then applied the DATE format to the cells.&lt;/P&gt;
&lt;P&gt;This is what i get for the first few rows (tab delimited text with a blank column to help readability)&lt;/P&gt;
&lt;PRE&gt;LASTPAY		After Text to column and apply date format.
42887		6/1/2017
6/24/2017		6/24/2017
42887		6/1/2017
42917		7/1/2017
42906		6/20/2017
2017-06-30		6/30/2017
42911		6/25/2017
6/30/2017		6/30/2017
42917		7/1/2017
42916		6/30/2017
42907		6/21/2017
42887		6/1/2017
42916		6/30/2017
42901		6/15/2017
42905		6/19/2017
42908		6/22/2017
42916		6/30/2017
42917		7/1/2017
42922		7/6/2017
42907		6/21/2017
42923		7/7/2017
42915		6/29/2017&lt;/PRE&gt;
&lt;P&gt;I suspect that&amp;nbsp;your process somewhere along the line turned most of your dates into character values after removing the date format for some reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 20:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391009#M66199</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-25T20:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391013#M66200</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;: You have more courage than I do. I attempted to open the file using Chrome's fairly safe viewer, but it was unable to open the file so I decided not to open it in Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 20:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391013#M66200</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-25T20:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391015#M66201</link>
      <description>&lt;P&gt;Ya I think that's the problem - unfortunately, all I have is a serveral million observations with that glitch in it and I can't really go back to the source and ask them to fix the raw variables (the dataset is an amalgation of multiple sources, all with different formats) - so I was hoping that I could somehow just fix it within SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 20:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391015#M66201</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-08-25T20:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391019#M66202</link>
      <description>&lt;P&gt;This question has come up before. &amp;nbsp;Basically you have a column in Excel that has mixed dates and character strings. So when you convert it into a SAS dataset using PROC IMPORT or LIBNAME engine SAS will set the variable type to character. The dates come over as the text version of the integer value that EXCEL uses for dates. &amp;nbsp;You just need to convert them. &amp;nbsp;I would test if the value is an integer and then convert the integer by correcting for the difference in offset dates. And then use the ANYDTDTE informat to convert the other values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  date = input(chardate,??11.);
  if missing(date) then date=input(chardate,anydtdte11.);
  else date=date + '01JAN1900'd -2 ;
  format date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The -2 in the conversion formula is because SAS starts counting from zero and Excel starts counting from one and Excel mistakenly thinks that 1900 was a leap year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you could still have trouble if your multiple sources come from locations where people use MDY ordering for dates and also from places where people use DMY ordering for dates. In that case there really is no way to tell which is the right date without some additional knowledge. &amp;nbsp;For example if you know the dates should always be the first of the month then you would know the '1/7/2017' meant 01JUL2017 and not 07JAN2017. &amp;nbsp;Or if you know the source location of the record you could use that. &amp;nbsp;Otherwise there will be no way to convert a value like '10/12/2016' with 100% convidence.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 21:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391019#M66202</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-25T21:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391020#M66203</link>
      <description>&lt;P&gt;This code I found much more accurate:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; work.want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set work.have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format datenew date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datenew =input(datehave,8.)-21916;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if missing(datenew ) then datenew =input(datehave,anydtdte10.);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 21:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391020#M66203</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-08-25T21:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391021#M66204</link>
      <description>I found this one to be quite helpful:&lt;BR /&gt;data work.want;&lt;BR /&gt;&lt;BR /&gt;set work.have;&lt;BR /&gt;&lt;BR /&gt;format datenew date9.;&lt;BR /&gt;&lt;BR /&gt;datenew =input(datehave,8.)-21916;&lt;BR /&gt;&lt;BR /&gt;if missing(datenew ) then datenew =input(datehave,anydtdte10.);&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Aug 2017 21:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391021#M66204</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-08-25T21:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391023#M66205</link>
      <description>&lt;P&gt;I prefer the order the way I proposed as, otherwise, a date like 20170630 doesn't translate correctly and you end up with all kinds of notes in your log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 21:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391023#M66205</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-25T21:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting non-homogenous dates to SAS dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391029#M66206</link>
      <description>&lt;P&gt;If you only have to process this one time I would suggest the Open in Excel, highlight and change text to numeric approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have to do this frequently I would start documenting how much time this takes as eventually what ever approach you take that works with this file is likely to fail, hopefully no date at all rather than a date that causes more issues later, and will need additional time to identify and correct.&lt;/P&gt;
&lt;P&gt;At some point you may have documented enough time=man hours=Co$t to the organization that the process at least gets reviewed.&lt;/P&gt;
&lt;P&gt;It may be there is no formal data "agreement" for combining the multiple data sources as to what goes in which column, what format and what file type. A lack of this type is common cause of "weird" data issues such as you are experiencing. There may be other people upstream of you that are also having issues around combining this data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I decided long ago that I would avoid using actual Excel files for interchange because of the file size limits. Once upon a time 64K rows was the limit and I routinely dealt with orders of magnitude above that. Having someone try to tell me to process 10 or 100 files after spitting the data apart just to use Excel (and why? they couldn't actually do anything in Excel without the whole data set) was a waste of everyones time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 22:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Converting-non-homogenous-dates-to-SAS-dates/m-p/391029#M66206</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-25T22:19:04Z</dc:date>
    </item>
  </channel>
</rss>

