<?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: Changing data values with date formats not working properly and giving me the wrong dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/788993#M252409</link>
    <description>&lt;P&gt;Thank you for your response. Where would I put that in my code (and can you post an example)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jan 2022 23:35:04 GMT</pubDate>
    <dc:creator>carmong</dc:creator>
    <dc:date>2022-01-07T23:35:04Z</dc:date>
    <item>
      <title>Changing data values with date formats not working properly and giving me the wrong dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/788956#M252382</link>
      <description>&lt;P&gt;I am attempting to change the appearance of Data values with date formats, but the dates are not converting property and giving me the wrong dates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to change DATETIME19. to a different format but the dates are coming out wrong (I would like to have it in the mmddyy format but tried other formats)&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used the following code:&lt;/P&gt;&lt;P&gt;data deltbl; set deletion;&lt;BR /&gt;date2 = input(AdmitDate,anydtdte10.);&lt;BR /&gt;format date2 date9.;&lt;BR /&gt;datec = put(date2,date9.);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried the following to change mmddyy.10 and it still isn't coming out right&lt;/P&gt;&lt;P&gt;data deltbl; set deletion;&lt;BR /&gt;date2 = input(AdmitDate,anydtdte10.);&lt;BR /&gt;format date2 mmddyy10.;&lt;BR /&gt;addate = put(date2,mmddyy10.);&lt;BR /&gt;hosp =catx("_", ref_HospitalCode, MRN, addate);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sample date errors 2 jpeg.jpg" style="width: 369px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67211i91849CFB2DE47B04/image-size/large?v=v2&amp;amp;px=999" role="button" title="sample date errors 2 jpeg.jpg" alt="sample date errors 2 jpeg.jpg" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sample date errors jpeg.jpg" style="width: 395px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67212iAE5741D0860E3337/image-size/large?v=v2&amp;amp;px=999" role="button" title="sample date errors jpeg.jpg" alt="sample date errors jpeg.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 20:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/788956#M252382</guid>
      <dc:creator>carmong</dc:creator>
      <dc:date>2022-01-07T20:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data values with date formats not working properly and giving me the wrong dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/788962#M252384</link>
      <description>&lt;P&gt;Your code is mostly correct except you have a date time, not a date. Use the Datepart() function on the variable to get only the date portion.&amp;nbsp;&lt;BR /&gt;Use ANYDTDTM to read in a date time instead of date.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411970"&gt;@carmong&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am attempting to change the appearance of Data values with date formats, but the dates are not converting property and giving me the wrong dates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to change DATETIME19. to a different format but the dates are coming out wrong (I would like to have it in the mmddyy format but tried other formats)&lt;/P&gt;
&lt;DIV class=""&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have used the following code:&lt;/P&gt;
&lt;P&gt;data deltbl; set deletion;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;date2 =datepart( input(AdmitDate,anydtdtm.));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;format date2 date9.;&lt;BR /&gt;datec = put(date2,date9.);&lt;BR /&gt;run;&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="sample date errors 2 jpeg.jpg" style="width: 369px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67211i91849CFB2DE47B04/image-size/large?v=v2&amp;amp;px=999" role="button" title="sample date errors 2 jpeg.jpg" alt="sample date errors 2 jpeg.jpg" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sample date errors jpeg.jpg" style="width: 395px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67212iAE5741D0860E3337/image-size/large?v=v2&amp;amp;px=999" role="button" title="sample date errors jpeg.jpg" alt="sample date errors jpeg.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jan 2022 18:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/788962#M252384</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-08T18:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data values with date formats not working properly and giving me the wrong dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/788993#M252409</link>
      <description>&lt;P&gt;Thank you for your response. Where would I put that in my code (and can you post an example)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 23:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/788993#M252409</guid>
      <dc:creator>carmong</dc:creator>
      <dc:date>2022-01-07T23:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data values with date formats not working properly and giving me the wrong dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/789000#M252411</link>
      <description>&lt;P&gt;The INPUT function is for converting character strings into values.&amp;nbsp; But your variable appears to be a DATETIME numeric variable, not a character string.&amp;nbsp; If you try to use a number as the first parameter to the INPUT() function SAS will have to first convert it to a character string.&amp;nbsp; It will use the BEST12. format to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS stores DATETIME values as number of seconds.&amp;nbsp; Midnight on the 8th of May in 2020 is the number&amp;nbsp;1,904,515,200 which when printed using the BEST12. format will be the string "&amp;nbsp;&amp;nbsp;1904515200".&amp;nbsp; Since your informat is only using the first 10 characters that will look like the string 19045152.&amp;nbsp; Which only makes sense as a date if you treat is as DDMMYYYY style.&amp;nbsp; Hence you have created the date of APR 19, 5152.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;You just want to use the DATEPART() function to convert the number of seconds in your datetime variable to a number of days.&amp;nbsp; Then you can use the DATE format to display it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data deltbl;
  set deletion;
  date2 = datepart(AdmitDate);
  format date2 date9.;
  datec = put(date2,date9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Or you could leave your variable as DATETIME and use the DTDATE format to display just the date part.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 23:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/789000#M252411</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-07T23:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data values with date formats not working properly and giving me the wrong dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/789062#M252443</link>
      <description>I modified your code in the answer.</description>
      <pubDate>Sat, 08 Jan 2022 18:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-data-values-with-date-formats-not-working-properly-and/m-p/789062#M252443</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-08T18:31:05Z</dc:date>
    </item>
  </channel>
</rss>

