<?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: How to convert a character variable to a numeric date type variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262891#M51423</link>
    <description>&lt;P&gt;You need to convert the character string to numeric then apply a format to the numeric:&lt;/P&gt;
&lt;PRE&gt;data want;
  char_date="2015-01-01";
  entry_date=input(char_date,yymmdd10.);
  format entry_date date9.;
run;
&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Apr 2016 13:17:55 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-04-11T13:17:55Z</dc:date>
    <item>
      <title>How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262884#M51418</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;BR /&gt;&lt;BR /&gt;I try to convert one of my character columns into a date one.&lt;BR /&gt;&lt;BR /&gt;The following statement works fine but..&lt;BR /&gt;&lt;BR /&gt;data H_finished;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set work.finished;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; format entry_date date9.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;problem :&lt;BR /&gt;&lt;BR /&gt;The column type remains character. If I use the format I acutally want E8601DNw. I get the error:&lt;BR /&gt;"An operation that opens a SAS® data set in SAS® Enterprise Guide® fails with the error "Format names must start with an English letter" The dates are already correctly formatted yyyy-mm-dd just as a character.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262884#M51418</guid>
      <dc:creator>metallon</dc:creator>
      <dc:date>2016-04-11T13:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262888#M51421</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are only 2 type of variables within sas: character and numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at input function to convert your character variable to a numeric one and afterwards you can apply whatever format you like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000180357.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000180357.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262888#M51421</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-04-11T13:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262889#M51422</link>
      <description>&lt;P&gt;You'll need to give some examples of what ENTRY_DATE actually contains.&amp;nbsp; And if it's not 100% obvious, please provide what dates those represent.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262889#M51422</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-11T13:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262891#M51423</link>
      <description>&lt;P&gt;You need to convert the character string to numeric then apply a format to the numeric:&lt;/P&gt;
&lt;PRE&gt;data want;
  char_date="2015-01-01";
  entry_date=input(char_date,yymmdd10.);
  format entry_date date9.;
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/262891#M51423</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-11T13:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263146#M51489</link>
      <description>Hi RW9&lt;BR /&gt;&lt;BR /&gt;A character date like '2015-10-01'&lt;BR /&gt;becomes '   203'&lt;BR /&gt;&lt;BR /&gt;data H_finished;&lt;BR /&gt;   set work.finished;&lt;BR /&gt;    entry_date=input(entry_date,E8601DNw.);&lt;BR /&gt;   format entry_date date9.;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 12 Apr 2016 11:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263146#M51489</guid>
      <dc:creator>metallon</dc:creator>
      <dc:date>2016-04-12T11:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263153#M51491</link>
      <description>&lt;P&gt;Yes, you need to read the date in the format it is in."2015-10-01" is YYMMDD10 format, not e8601:&lt;/P&gt;
&lt;PRE&gt;data H_finished;
  set work.finished;
  entry_date=input(entry_date,yymmdd10.);
  format entry_date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;See formats for examples of structure:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 12:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263153#M51491</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-12T12:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263159#M51492</link>
      <description>&lt;P&gt;YYMMDD10 has 2 digits for year&lt;BR /&gt;E8601DNw. has 4 digits for year, like I do e.g. 2015&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 12:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263159#M51492</guid>
      <dc:creator>metallon</dc:creator>
      <dc:date>2016-04-12T12:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263161#M51493</link>
      <description>anyway. even if I use your suggested format it does not work:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;  char_date="2015-01-01";&lt;BR /&gt;  entry_date=input(char_date,yymmdd10.);&lt;BR /&gt;  format entry_date date9.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;turns out to be 01JAN2015 and I need 2015-01-01.&lt;BR /&gt;&lt;BR /&gt;when I use&lt;BR /&gt;&lt;BR /&gt;data H_finished;&lt;BR /&gt;  set work.finished;&lt;BR /&gt;  entry_date=input(entry_date,yymmdd10.);&lt;BR /&gt;  format entry_date date9.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;the date still turns out as '      203'&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Apr 2016 12:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263161#M51493</guid>
      <dc:creator>metallon</dc:creator>
      <dc:date>2016-04-12T12:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263167#M51494</link>
      <description>&lt;P&gt;In SAS, the format that expresses a date as YYYY-MM-DD is called yymmddd10.&amp;nbsp; So to express dates in that format, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt; char_date="2015-01-01";&lt;BR /&gt; entry_date=input(char_date,yymmdd10.);&lt;BR /&gt; format entry_date yymmddd10.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 12:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263167#M51494</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-12T12:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263168#M51495</link>
      <description>&lt;P&gt;Sorry, you don't seem to understand formats. &amp;nbsp;Lets take the code:&lt;/P&gt;
&lt;PRE&gt;data H_finished;
  set work.finished;
  entry_date=input(entry_date,yymmdd10.);
  format entry_date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;What this does is create a numeric variable called entry_date (all dates in SAS are numeric - a number of days since a certain timepoint) (This may be where problem arises, if your entry_date is character, you wouldnt put the numeric back into it, it needs to go into a new numeric field). &amp;nbsp;To read text in as a date value, I use the input() function, this takes two parameters - the text, and the informat to read that text as. &amp;nbsp;YYMMDD10. is a format that reads data as: year as either 2 or 4 length, month as 2, and day as 2. &amp;nbsp;As I specify the length of the informat as 10, this will read the data as YYYY-MM-DD, which you will see is 10 characters. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Entry date will then contain the number of days since a base point, 01jan1966 or something like that, so you will see an odd number if you do not format that number. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the secon line, the format entry_date date9. tells SAS to display this number of days, in the format provided, in the above case this will be displayed using the date format, with 9 characters, eg. DDMONYYYY.&lt;/P&gt;
&lt;P&gt;See this example:&lt;/P&gt;
&lt;PRE&gt;data H_finished;&lt;BR /&gt; entry_date="2015-10-02";&lt;BR /&gt; new_date=input(entry_date,yymmdd10.);&lt;BR /&gt; yymmdd_date=new_date;&lt;BR /&gt; format new_date date9.;&lt;BR /&gt; format yymmdd_date yymmdd10.;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Run it as is - and you will see the various variables. &amp;nbsp;Note that you wouldn't want to put a numeric back into character.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 12:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263168#M51495</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-12T12:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263481#M51568</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to do only this small step and receive the warning&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"NOTE 485-185: Informat YYMMDDD was not found or could not be loaded."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The column entry_date_new is empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;62&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;63&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data H_finished_new;&lt;BR /&gt;64&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set work.H_finished;&lt;BR /&gt;65&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;66&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; entry_date_new=input(entry_date,yymmddd10.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __________&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 485&lt;BR /&gt;NOTE 485-185: Informat YYMMDDD was not found or could not be loaded.&lt;BR /&gt;&lt;BR /&gt;67&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 11:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263481#M51568</guid>
      <dc:creator>metallon</dc:creator>
      <dc:date>2016-04-13T11:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character variable to a numeric date type variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263490#M51569</link>
      <description>&lt;P&gt;Correct the typo in the format and it will work. &amp;nbsp;The format is YYMMDD, and the length is 10, thus: YYMMDD10.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 12:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-variable-to-a-numeric-date-type/m-p/263490#M51569</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-13T12:58:41Z</dc:date>
    </item>
  </channel>
</rss>

