<?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: Date fromatting in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979838#M378863</link>
    <description>&lt;P&gt;For which purpose do you need that number? It cannot be used in further analysis, and if you need to export data in this format, the YYMMDDN format can handle this without conversion.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Dec 2025 08:39:01 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2025-12-02T08:39:01Z</dc:date>
    <item>
      <title>Date fromatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979754#M378844</link>
      <description>&lt;P&gt;I am attempting to run the following line of code to format a date for me as an integer instead: Date1=SUBSTR(End_Date,1,8)*1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This changes the date '2014-10-04' to '2' when really I want it to be an integer that looks like this '20141004'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2025 09:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979754#M378844</guid>
      <dc:creator>markstringer</dc:creator>
      <dc:date>2025-12-01T09:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Date fromatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979755#M378845</link>
      <description>&lt;P&gt;There is a built-in format YYMMDDN. in sas to get it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
End_Date='2014-10-04' ;
Date1=input(End_Date,yymmdd10.);
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;format Date1 yymmddn8.;&lt;/STRONG&gt;&lt;/FONT&gt;

put _all_;
run;&lt;/PRE&gt;
&lt;PRE&gt;1    data _null_;
2    End_Date='2014-10-04' ;
3    Date1=input(End_Date,yymmdd10.);
4    format Date1 yymmddn8.;
5
6    put _all_;
7    run;

End_Date=2014-10-04 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Date1=20141004&lt;/STRONG&gt;&lt;/FONT&gt; _ERROR_=0 _N_=1
NOTE: “DATA 语句”所用时间（总处理时间）:
      实际时间          0.40 秒
      CPU 时间          0.01 秒

&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Dec 2025 09:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979755#M378845</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-12-01T09:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Date fromatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979774#M378848</link>
      <description>&lt;P&gt;The internal value of date1 is a SAS date. If you want an integer in the form yyyymmdd, then you can use the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;8    data test;
9    End_Date='2014-10-04' ;
10   Date1=input(End_Date,yymmdd10.);
11   *format Date1 yymmddn8.;
12   daten=input(compress(end_date,'-'),8.);
13   put _all_;
14   run;

End_Date=2014-10-04 Date1=20000 daten=20141004 _ERROR_=0 _N_=1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Dec 2025 12:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979774#M378848</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-12-01T12:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Date formatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979775#M378849</link>
      <description>&lt;P&gt;So&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;has already given you the answer, however, I would like to point out an important principle. Best practice is to handle dates using date functions and date formats and date informats, if at all possible. And to do this, you need to know if the value of End_Date (which you claim is&amp;nbsp;&lt;SPAN&gt;'2014-10-04') is really character, or really numeric. If, as Ksharp guessed, the variable End_Date is character (is it?) then you need to use an informat (which in Ksharp's code is&amp;nbsp;yymmdd10.). If End_Date was numeric, then you could use a format to convert it to the desired appearance.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2025 14:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979775#M378849</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-12-01T14:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Date fromatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979795#M378853</link>
      <description>&lt;P&gt;If END_DATE is actually a DATE value then the reason you get 2 is because the actual number that SAS uses to represent the 4th day in October of 2014 is 20,000.&amp;nbsp; Since you asked SAS to convert that into a string so it could be used as the argument to the SUBSTR() function it used the BEST12. format so the result was 7 spaces followed by the 5 digit string 20000.&amp;nbsp; You then picked only the 7 spaces and the '2'.&amp;nbsp; And then forced SAS to convert that string into the number 2 which you multiplied by 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If END_DATE is instead a CHARACTER variabel it would also need to have those some 7 leading spaces for the result to be 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt; 71         data _null_;
 72           end_date= '04OCT2014'd;
 73           Date1=SUBSTR(End_Date,1,8)*1;
 74           put (_all_) (=/);
 75         run;
 
 NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
       73:16   
 NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
       73:9   
 end_date=20000
 Date1=2
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 76         
 77         data _null_;
 78           end_date= '       2014-10-04';
 79           Date1=SUBSTR(End_Date,1,8)*1;
 80           put (_all_) (=/);
 81         run;
 
 NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
       79:9   
 end_date=2014-10-04
 Date1=2
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;If you want to convert a STRING like '2014-10-04' into a DATE then using the INPUT() function and the YYMMDD &lt;STRONG&gt;informat&lt;/STRONG&gt;.&amp;nbsp; Make sure tor remove the leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;actual_date = input(left(end_date),yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the value of ACTUAL_DATE to print in the style YYYYMMDD then attach the YYMMDDN &lt;STRONG&gt;format&lt;/STRONG&gt; to it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format actual_date yymmddn8.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to make the variable DATE1 be a NUMBER in the style YY,YYM,MDD then use the PUT() function with YYMMDDN8. format to convert the date into a string so you can then use the INPUT() function with the normal numeric informat of 8. to convert that string back into a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date1 = input(put(actual_date,yymmddn8.),8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2025 17:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979795#M378853</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-01T17:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Date fromatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979803#M378856</link>
      <description>&lt;P&gt;As a side note to Tom's very thorough explanation (thanks!), many people think the NOTE in the log about automatic type conversion should be treated as an error, to avoid problems like this.&amp;nbsp; Many log scanners are coded to treat this NOTE as not allowed to appear in a log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is an undocumented system option which will allow you to turn this problematic NOTE (and others) into an actual error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    options dsoptions=note2err ;
2    data _null_;
3      end_date= '04OCT2014'd;
4      Date1=SUBSTR(End_Date,1,8)*1;
ERROR: Numeric value found where character value needed at line 4 column 16.
ERROR: Character value found where numeric value needed at line 4 column 9.
5      put (_all_) (=/);
6    run;

NOTE: The SAS System stopped processing this step because of errors.
&lt;/PRE&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>Mon, 01 Dec 2025 19:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979803#M378856</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-12-01T19:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Date fromatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979838#M378863</link>
      <description>&lt;P&gt;For which purpose do you need that number? It cannot be used in further analysis, and if you need to export data in this format, the YYMMDDN format can handle this without conversion.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2025 08:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979838#M378863</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-12-02T08:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Date formatting in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979972#M378876</link>
      <description>&lt;P&gt;In addition to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s very good suggestion, if you find yourself needing a date, time or datetime value to appear in a specific way and none of the very many SAS supplied formats do not quite get you there you can use Proc Format to create your own.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One caveat with custom date/time/datetime formats is that they may not work as axis labels in graphs.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Dec 2025 22:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-fromatting-in-SAS/m-p/979972#M378876</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-12-03T22:19:52Z</dc:date>
    </item>
  </channel>
</rss>

