<?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: change character date format into numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519533#M140720</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230936"&gt;@Songchan&lt;/a&gt;&amp;nbsp; At compile time, SAS creates and stores the metadata/descriptor portion of the variables. Therefore, at execution you will need a new variable to stored the converted values, i.e in your case the converted char&amp;nbsp; date to num sas date.&amp;nbsp; This essentially means a new assignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   numeric_sas_Date=  input (char_date, yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above states, you want to create a numeric sas date by reading nonstandard character date using the appropriate informat which is yymmdd10. This is what Paigemiller demonstrated earlier. I chimed in only to help you understand.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Dec 2018 20:02:35 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-12-07T20:02:35Z</dc:date>
    <item>
      <title>change character date format into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519508#M140709</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The current date format is yyyy-mm-dd, and proc contents shows the formate is $10, i want to change it into numeric format, but the following codes don't work. could anyone help me to find the reason?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp01; set temp01;
     date1=input(date,$10.);
	 format date1 mmddyy8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Dec 2018 18:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519508#M140709</guid>
      <dc:creator>Songchan</dc:creator>
      <dc:date>2018-12-07T18:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: change character date format into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519511#M140711</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230936"&gt;@Songchan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;The current date format is yyyy-mm-dd,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Okay, stop right there! It is yyyy-mm-dd, so don't&amp;nbsp;convert&amp;nbsp;using&amp;nbsp;$10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use&amp;nbsp;the appropriate informat that recognizes it as a calendar date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date1=input(date,yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 18:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519511#M140711</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-07T18:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: change character date format into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519515#M140713</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230936"&gt;@Songchan&lt;/a&gt;&amp;nbsp;The way to think through intuitively is to understand the proc contents report. Since your proc contents report says the date is a character date, it is not stored as a number. When we talk of character date to be converted to a numeric date aka SAS date, we are basically dealing with something known as non standard data which could be a mix of chars/nums etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically we read non standard data with tools known as informats. Informats will read the number of bytes of values in the variable specified in it, and convert the value to a valid number in your case and therefore the requirement is to appropriate with a compatible informat which is yymmdd10. as opposed to character format $10.&amp;nbsp; Should the informat fail to read the nonstandard data and convert appropriately, it triggers the automatic variable _ERROR_=1 and writes a note to the log and writes a missing value. Of course there are certain modifiers, that can used to suppress this behavior but that is out of scope for your rather straight forward requirement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH &amp;amp; Regards!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230936"&gt;@Songchan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The current date format is yyyy-mm-dd, and proc contents shows the formate is $10, i want to change it into numeric format, but the following codes don't work. could anyone help me to find the reason?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp01; set temp01;
     date1=input(date,$10.);
	 format date1 mmddyy8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 19:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519515#M140713</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-07T19:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: change character date format into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519531#M140719</link>
      <description>&lt;P&gt;Thank you for replying me, do you mean i can write like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;data temp01; set temp01;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; input (date, yymmdd10.);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; format date yymmddn8.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It still doesn't work.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 19:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519531#M140719</guid>
      <dc:creator>Songchan</dc:creator>
      <dc:date>2018-12-07T19:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: change character date format into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519533#M140720</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230936"&gt;@Songchan&lt;/a&gt;&amp;nbsp; At compile time, SAS creates and stores the metadata/descriptor portion of the variables. Therefore, at execution you will need a new variable to stored the converted values, i.e in your case the converted char&amp;nbsp; date to num sas date.&amp;nbsp; This essentially means a new assignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   numeric_sas_Date=  input (char_date, yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above states, you want to create a numeric sas date by reading nonstandard character date using the appropriate informat which is yymmdd10. This is what Paigemiller demonstrated earlier. I chimed in only to help you understand.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 20:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519533#M140720</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-07T20:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: change character date format into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519536#M140722</link>
      <description>&lt;P&gt;&amp;nbsp;Thank you so much! That works!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 20:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-character-date-format-into-numeric/m-p/519536#M140722</guid>
      <dc:creator>Songchan</dc:creator>
      <dc:date>2018-12-07T20:08:12Z</dc:date>
    </item>
  </channel>
</rss>

