<?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 Convert Text to Date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-to-Date-format/m-p/72173#M15565</link>
    <description>In SAS 9, I have a table that has a text field that holds information that is a date in YYYYMMDD format.  I need to convert this data to a date format as I need to do comparisons on this field.&lt;BR /&gt;
&lt;BR /&gt;
Some samples from the field would be:&lt;BR /&gt;
&lt;BR /&gt;
20081002&lt;BR /&gt;
20070417&lt;BR /&gt;
20080101&lt;BR /&gt;
&lt;BR /&gt;
The field these are stored in is a text field.  How can I make this data workable if I need to compare it to another date, say finding all data that is within the last year.  &lt;BR /&gt;
&lt;BR /&gt;
Thanx.&lt;BR /&gt;
Andy</description>
    <pubDate>Tue, 03 Feb 2009 16:16:51 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-02-03T16:16:51Z</dc:date>
    <item>
      <title>Convert Text to Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-to-Date-format/m-p/72173#M15565</link>
      <description>In SAS 9, I have a table that has a text field that holds information that is a date in YYYYMMDD format.  I need to convert this data to a date format as I need to do comparisons on this field.&lt;BR /&gt;
&lt;BR /&gt;
Some samples from the field would be:&lt;BR /&gt;
&lt;BR /&gt;
20081002&lt;BR /&gt;
20070417&lt;BR /&gt;
20080101&lt;BR /&gt;
&lt;BR /&gt;
The field these are stored in is a text field.  How can I make this data workable if I need to compare it to another date, say finding all data that is within the last year.  &lt;BR /&gt;
&lt;BR /&gt;
Thanx.&lt;BR /&gt;
Andy</description>
      <pubDate>Tue, 03 Feb 2009 16:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-to-Date-format/m-p/72173#M15565</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-03T16:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text to Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-to-Date-format/m-p/72174#M15566</link>
      <description>Hi: &lt;BR /&gt;
&lt;BR /&gt;
  You might want to investigate the INPUT function. For example, if your text field was called CHARSTR, then you could create a numeric variable from the character field by using the INPUT statement:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  newdate = input(charstr,yymmdd8.);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
In this instance, (inside a DATA step program), the new variable NEWDATE would be numeric, would be internally stored as the number of days since Jan 1, 1960, and could be formatted with any of the SAS date formats.&lt;BR /&gt;
&lt;BR /&gt;
You could then do comparisons or test conditions using NEWDATE like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  if year(newdate) = 2007 . . .&lt;BR /&gt;
or&lt;BR /&gt;
  if newdate lt '01Jan2008'd . . .&lt;BR /&gt;
or&lt;BR /&gt;
  if year(newdate - 180) = 2007 . . .&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
ps...there have been a lot of previous forum postings on the conversion of character dates to SAS date values. A search of the forum, might get you some more code examples.</description>
      <pubDate>Tue, 03 Feb 2009 16:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-to-Date-format/m-p/72174#M15566</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-02-03T16:29:25Z</dc:date>
    </item>
  </channel>
</rss>

