<?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: I need a little help formatting dates! in SAS Software for Learning Community</title>
    <link>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950685#M2442</link>
    <description>&lt;P&gt;Thanks , that was what I needed.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Nov 2024 19:56:32 GMT</pubDate>
    <dc:creator>davidjayjackson</dc:creator>
    <dc:date>2024-11-13T19:56:32Z</dc:date>
    <item>
      <title>I need a little help formatting dates!</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950637#M2438</link>
      <description>&lt;P&gt;When the date is imported it is formatted like this:&amp;nbsp;&lt;SPAN&gt;12/01/2023 (&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;SalesDate&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;MMDDYY10.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run this code, it deletes the dates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Convert SalesDate from character to SAS date format */&lt;BR /&gt;data esales.import;&lt;BR /&gt;set esales.import;&lt;BR /&gt;/* Convert SalesDate to SAS date using MM/DD/YYYY format */&lt;BR /&gt;SalesDate = input(SalesDate, mmddyy10.);&lt;BR /&gt;format SalesDate date9.; /* Format for readability as DDMMMYYYY */&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 18:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950637#M2438</guid>
      <dc:creator>davidjayjackson</dc:creator>
      <dc:date>2024-11-13T18:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: I need a little help formatting dates!</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950638#M2439</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/470920"&gt;@davidjayjackson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;When the date is imported it is formatted like this:&amp;nbsp;&lt;SPAN&gt;12/01/2023 (&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;SalesDate&lt;/TD&gt;
&lt;TD&gt;Num&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;MMDDYY10.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this code, it deletes the dates:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* Convert SalesDate from character to SAS date format */&lt;BR /&gt;data esales.import;&lt;BR /&gt;set esales.import;&lt;BR /&gt;/* Convert SalesDate to SAS date using MM/DD/YYYY format */&lt;BR /&gt;SalesDate = input(SalesDate, mmddyy10.);&lt;BR /&gt;format SalesDate date9.; /* Format for readability as DDMMMYYYY */&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See comments on your code below. General idea:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do not use the same name in SET/DATA statements. This overwrites the data so it has to be recreated before it can be used again.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Dates in SAS are stored as numerics with a date format. To change the format, use a format statement&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;To fix your code first re-import your data, then try something like below.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data esales.import_date_formatted;
set esales.import;
format SalesDate date9.; /* Format for readability as DDMMMYYYY */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you still have issues, please post your log and full code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 18:52:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950638#M2439</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-11-13T18:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: I need a little help formatting dates!</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950649#M2440</link>
      <description>&lt;P&gt;So SALESDATE is a numeric variable with DATE values. So there is no need to change the value to change how the value is displayed.&amp;nbsp; Just attach a different display format to the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets nolist lib=esales ;
  modify import;
    format SalesDate date9.;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is wrong with your program?&amp;nbsp; The INPUT() function needs a character string, not a number.&amp;nbsp; So SAS will first&amp;nbsp;convert that date value into a character string using the BEST12. format.&amp;nbsp; &amp;nbsp;Then the MMDDYY10. informat will try to read in the first 10 characters of that string and interpret that as if is a date value in MDY order (possibly with delimiters between the parts).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's try if on just a single date and see what happens.&lt;/P&gt;
&lt;PRE&gt;476  data test;
477    startdate = '01MAY2024'd ;
478    string = put(startdate,best12.);
479    newdate = input(string,mmddyy10.);
480    put startdate=comma. startdate=mmddyy10. startdate=date9.
481      / string=$quote.
482      / newdate=comma. newdate=date9.
483    ;
484  run;

NOTE: Invalid argument to function INPUT at line 479 column 13.
startdate=23,497 startdate=05/01/2024 startdate=01MAY2024
string="       23497"
newdate=. newdate=.
startdate=23497 string=23497 newdate=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 479:13
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.04 seconds
&lt;/PRE&gt;
&lt;P&gt;So the date 01MAY2024 is the number&amp;nbsp;23,497.&amp;nbsp; When converted to a string using the BEST12. format there will be 7 leading spaces, so the first 10 characters is just '&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;234' which does not look like a date in MDY style.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 19:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950649#M2440</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-13T19:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: I need a little help formatting dates!</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950685#M2442</link>
      <description>&lt;P&gt;Thanks , that was what I needed.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 19:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/I-need-a-little-help-formatting-dates/m-p/950685#M2442</guid>
      <dc:creator>davidjayjackson</dc:creator>
      <dc:date>2024-11-13T19:56:32Z</dc:date>
    </item>
  </channel>
</rss>

