<?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: Convert Numeric to Date in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/333050#M22150</link>
    <description>&lt;P&gt;I want to add 3 months to a character date variable. Here is what I did:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Convert the character date to a number and added 3 months (used 90 days) to that number&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;input(LN_DC,mmddyy10.)+90&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Now I want to display results in (1) as a date in format ddmmmyyyy. I am having a lot of difficulty in doing this. As I read the help,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;put(input(LN_DC,mmddyy10.)+90),mmddyy10.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; should do it. Obviously I am wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me? Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Amin&lt;/P&gt;</description>
    <pubDate>Wed, 15 Feb 2017 15:29:09 GMT</pubDate>
    <dc:creator>AminB</dc:creator>
    <dc:date>2017-02-15T15:29:09Z</dc:date>
    <item>
      <title>Convert Numeric to Date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3711#M1196</link>
      <description>I have a variable 'date' which stores dates as numbers, eg: 20070202.  Although I know this is a date SAS just sees a number.  How can I convert this to a date format so I can then use it to calculate someones age?</description>
      <pubDate>Wed, 04 Jul 2007 09:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3711#M1196</guid>
      <dc:creator>Ted</dc:creator>
      <dc:date>2007-07-04T09:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Numeric to Date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3712#M1197</link>
      <description>&lt;P&gt;Your problem is two-fold.&lt;BR /&gt; &lt;BR /&gt; You say that you have a number holding a date, but the format of that number is in fact a string of the apparent form Ccyymmdd. What you want to do is take that string and read it as a date.&lt;BR /&gt; &lt;BR /&gt; That is quite easy, requiring only that you use an Input() function with an appropriate informat. The structure of the informat is Yymmdd followed by a length. Personally, I use a length of 10 bytes, as if the fractional bars were still in the date, so select "Yymmdd10.".&lt;BR /&gt; &lt;BR /&gt; However, if you have a number of slightly more than 20 million that you are trying to convert, then you are trying to use an informat which expects a string value to read a number. SAS will then warn you of the conversion of a number to a character before it converts the value to a date. You get the result but at the request of an unnecessary message in the log.&lt;BR /&gt; &lt;BR /&gt; Dinosaur curmudgeons like me believe in handling data correctly so that when messages like these occur, we know something unexpected has happened. The conversion of 20 million to a string and then conversion to a date is not unexpected, so we code around these issues by handling the conversion with a format.&lt;BR /&gt; &lt;BR /&gt; Here is the code I used, in the log entry, and as you see, it is a clean interpretation of the data.&lt;BR /&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data TEST;
  DATENUM = 20070202;
  DATE = Input( Put( DATENUM, 8.), Yymmdd10.);
  Put DATE = Date9.;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;DATE=02FEB2007
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.46 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt; Kind regards&lt;BR /&gt; &lt;BR /&gt; David&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data value is CHARACTER, then use this technique from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. convert the character string representing a date (and stored in a character variable) to a numeric value representing a SAS date -&amp;gt; read the character string using a (date) INFORMAT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Write the SAS date (a number) as date using a (date-) FORMAT.&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  DateAsCharacter='20070202';
  DateAsNumber=input(DateAsCharacter,yymmdd8.);

  /* format DateAsNumber yymmdd10.;*/
  put DateAsNumber= DateAsNumber= yymmdd10. 
        DateAsNumber= eurdfdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 17:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3712#M1197</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2017-07-26T17:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Numeric to Date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3713#M1198</link>
      <description>I have a similar problem except the variable "date" is stored as 20070202, but it is a character variable,  how can i change that to a date format?  so the output would look like  2007-02-02</description>
      <pubDate>Tue, 28 Oct 2008 15:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3713#M1198</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-28T15:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Numeric to Date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3714#M1199</link>
      <description>DrewSAS&lt;BR /&gt;
&lt;BR /&gt;
SAS knows exactly 2 variable types: numeric and character.&lt;BR /&gt;
To read data you can use an INFORMAT to tell SAS how to interprete the data for reading, to write data you can use a FORMAT.&lt;BR /&gt;
&lt;BR /&gt;
SAS dates and datetimes are stored as numbers using NUMERIC variables.&lt;BR /&gt;
To write these numbers which represent a date you have to apply a (date-) format on these numeric variables.&lt;BR /&gt;
&lt;BR /&gt;
In your case:&lt;BR /&gt;
1. convert the character string representing a date (and stored in a character variable) to a numeric value representing a SAS date -&amp;gt; read the character string using a (date) INFORMAT.&lt;BR /&gt;
2. Write the SAS date (a number) as date using a (date-) FORMAT.&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  DateAsCharacter='20070202';&lt;BR /&gt;
  DateAsNumber=input(DateAsCharacter,yymmdd8.);&lt;BR /&gt;
/*  format DateAsNumber yymmdd10.;*/&lt;BR /&gt;
  put DateAsNumber= DateAsNumber= yymmdd10. DateAsNumber= eurdfdd10.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick</description>
      <pubDate>Wed, 29 Oct 2008 11:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/3714#M1199</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-10-29T11:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Numeric to Date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/333050#M22150</link>
      <description>&lt;P&gt;I want to add 3 months to a character date variable. Here is what I did:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Convert the character date to a number and added 3 months (used 90 days) to that number&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;input(LN_DC,mmddyy10.)+90&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Now I want to display results in (1) as a date in format ddmmmyyyy. I am having a lot of difficulty in doing this. As I read the help,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;put(input(LN_DC,mmddyy10.)+90),mmddyy10.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; should do it. Obviously I am wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me? Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Amin&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 15:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Numeric-to-Date/m-p/333050#M22150</guid>
      <dc:creator>AminB</dc:creator>
      <dc:date>2017-02-15T15:29:09Z</dc:date>
    </item>
  </channel>
</rss>

