<?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 number to date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560345#M156667</link>
    <description>&lt;P&gt;Your variable&amp;nbsp;&lt;EM&gt;is&lt;/EM&gt; a date. All you need to do is change the display format to your preferences.&lt;/P&gt;
&lt;P&gt;A length of 4 gives sufficient numeric precision for dates.&lt;/P&gt;</description>
    <pubDate>Tue, 21 May 2019 04:26:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-05-21T04:26:42Z</dc:date>
    <item>
      <title>convert number to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560258#M156626</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping someone here could help me figure out the solution to convert number to date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable called M0906_DC_TR_DTH_DT with length of 4, format as YYMMDDN8. in the original date set. It was shown as 20130513 for example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a trouble converting it into date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use the following code but it didn't work.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; DSCHRG_DT=input(put(M0906_DC_TR_DTH_DT, 8.), Yymmdd10.);   
	format DSCHRG_DT YYMMDDN8.;   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I also tried to change the length of&amp;nbsp;&lt;CODE class=" language-sas"&gt;M0906_DC_TR_DTH_DT to 8 instead of 4. But it didn't work neither.&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;The note showed 'Invalid argument to function INPUT ......'&lt;BR /&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help with this regard will be greatly appreciated!&lt;/SPAN&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 19:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560258#M156626</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2019-05-20T19:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: convert number to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560259#M156627</link>
      <description>&lt;P&gt;If the length of the variable is 4, i suspect the date is truncated to only 4 characters. It should have length of 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DSCHRG_DT=input('20130513', yymmdd10.);   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 19:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560259#M156627</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-05-20T19:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: convert number to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560265#M156628</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82725"&gt;@Crystal_F&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was hoping someone here could help me figure out the solution to convert number to date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable called M0906_DC_TR_DTH_DT with length of 4, format as YYMMDDN8. in the original date set. It was shown as 20130513 for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a trouble converting it into date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to use the following code but it didn't work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; DSCHRG_DT=input(put(M0906_DC_TR_DTH_DT, 8.), Yymmdd10.);   
	format DSCHRG_DT YYMMDDN8.;   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also tried to change the length of&amp;nbsp;&lt;CODE class=" language-sas"&gt;M0906_DC_TR_DTH_DT to 8 instead of 4. But it didn't work neither.&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;The note showed 'Invalid argument to function INPUT ......'&lt;BR /&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any help with this regard will be greatly appreciated!&lt;/SPAN&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If your variable shows that it has an existing format of YYMMDDN8. it is already a SAS date value.&lt;/P&gt;
&lt;P&gt;What do you mean by "show as a date"? Likely all you need to do is change the display format.&lt;/P&gt;
&lt;P&gt;You cannot change the length of a variable once created, and likely not needed.&lt;/P&gt;
&lt;P&gt;You should show desired result of what you attempt along with code.&lt;/P&gt;
&lt;P&gt;Here is an example of creating a variable of length 4 (number of bytes used to store a numeric, not related to display in any way) as a date value with a default format as you show and using a different format to display the value.&lt;/P&gt;
&lt;PRE&gt;data junk;
  length x 4.;
  x = today();
  format x yymmddn8.;
run;

proc print data=junk;
   title "Default format";
run;

proc print data=junk;
   title "Different format applied";
   format x worddate.;
run;title;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 19:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560265#M156628</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-20T19:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: convert number to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560345#M156667</link>
      <description>&lt;P&gt;Your variable&amp;nbsp;&lt;EM&gt;is&lt;/EM&gt; a date. All you need to do is change the display format to your preferences.&lt;/P&gt;
&lt;P&gt;A length of 4 gives sufficient numeric precision for dates.&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 04:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560345#M156667</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-21T04:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: convert number to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560537#M156769</link>
      <description>Boy! I made a very stupid mistake. Thanks for pointing out the problem. I don't need to do any conversion actually.</description>
      <pubDate>Tue, 21 May 2019 14:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560537#M156769</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2019-05-21T14:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: convert number to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560551#M156778</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If the length of the variable is 4, i suspect the date is truncated to only 4 characters. It should have length of 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DSCHRG_DT=input('20130513', yymmdd10.);   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FWIW, the largest value for length 4 is 2097152. Which "restricts" dates to a maximum of 23Oct7701.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 15:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-number-to-date/m-p/560551#M156778</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-21T15:28:41Z</dc:date>
    </item>
  </channel>
</rss>

