<?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 numeric value to SAS date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338798#M77227</link>
    <description>&lt;P&gt;As you will see on every post here, post some test data&amp;nbsp;&lt;STRONG&gt;in the form of a datastep.&lt;/STRONG&gt; &amp;nbsp;The code I provide below works fine, so what "does not work"?&lt;/P&gt;
&lt;PRE&gt;data have;
  date_num=20090930;
  date_var=input(put(date_num,best8.),yymmdd8.);
  format date_var date9.;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Mar 2017 13:54:26 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-03-07T13:54:26Z</dc:date>
    <item>
      <title>How to convert numeric value to SAS date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338794#M77226</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.3 and I have a variable "DATEOFDIAGNOSIS". When I look in the Column Attributes of the Viewtable, it has a format of BEST12. informat of BEST32., length is 8, and type is numeric (Example: 20090930). I would like to change this variable into a SAS date value, so I can use it to do date calculations. I want to have it in date9. informat.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried a bunch of different code after researching and in some cases, only some of the dates converted and others were left blank.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following codes and did not work:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data demo2;&lt;BR /&gt;set demo;&lt;BR /&gt;DATEOFDIAGNOSIS2 = input (put(DATEOFDIAGNOSIS, 12.), yymmdd8.);&lt;BR /&gt;format DATEOFDIAGNOSIS2 YYMMDD8.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data radtumorreg3;&lt;BR /&gt;set radtumorreg2;&lt;BR /&gt;char_var = put(DATEOFDIAGNOSIS,12.);&lt;BR /&gt;sas_date = input (char_var, mmddyy8.);&lt;BR /&gt;format sas_date date8.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 13:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338794#M77226</guid>
      <dc:creator>sy12345</dc:creator>
      <dc:date>2017-03-07T13:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert numeric value to SAS date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338798#M77227</link>
      <description>&lt;P&gt;As you will see on every post here, post some test data&amp;nbsp;&lt;STRONG&gt;in the form of a datastep.&lt;/STRONG&gt; &amp;nbsp;The code I provide below works fine, so what "does not work"?&lt;/P&gt;
&lt;PRE&gt;data have;
  date_num=20090930;
  date_var=input(put(date_num,best8.),yymmdd8.);
  format date_var date9.;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 13:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338798#M77227</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-07T13:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert numeric value to SAS date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338803#M77229</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132620"&gt;@sy12345&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS 9.3 and I have a variable "DATEOFDIAGNOSIS". When I look in the Column Attributes of the Viewtable, it has a format of BEST12. informat of BEST32., length is 8, and type is numeric (Example: 20090930). I would like to change this variable into a SAS date value, so I can use it to do date calculations. I want to have it in date9. informat.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a bunch of different code after researching and in some cases, only some of the dates converted and others were left blank.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following codes and did not work:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data demo2;&lt;BR /&gt;set demo;&lt;BR /&gt;DATEOFDIAGNOSIS2 = input (put(DATEOFDIAGNOSIS, 12.), yymmdd8.);&lt;BR /&gt;format DATEOFDIAGNOSIS2 YYMMDD8.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data radtumorreg3;&lt;BR /&gt;set radtumorreg2;&lt;BR /&gt;char_var = put(DATEOFDIAGNOSIS,12.);&lt;BR /&gt;sas_date = input (char_var, mmddyy8.);&lt;BR /&gt;format sas_date date8.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The problem is you are using w=12 in the PUT and that is RIGHT justified.&amp;nbsp; When you read CHAR_VAR with MMDDYY8 it only reads the first 8 characters 4 of which are blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change 12 to 8 or use the justification modifier 12.-L&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 14:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338803#M77229</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-03-07T14:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert numeric value to SAS date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338848#M77248</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132620"&gt;@sy12345&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS 9.3 and I have a variable "DATEOFDIAGNOSIS". When I look in the Column Attributes of the Viewtable, it has a format of BEST12. informat of BEST32., length is 8, and type is numeric (Example: 20090930). I would like to change this variable into a SAS date value, so I can use it to do date calculations. I want to have it in date9. informat.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a bunch of different code after researching and in some cases, only some of the dates converted and others were left blank.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following codes and did not work:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data demo2;&lt;BR /&gt;set demo;&lt;BR /&gt;DATEOFDIAGNOSIS2 = input (put(DATEOFDIAGNOSIS, 12.), yymmdd8.);&lt;BR /&gt;format DATEOFDIAGNOSIS2 YYMMDD8.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data radtumorreg3;&lt;BR /&gt;set radtumorreg2;&lt;BR /&gt;char_var =&lt;STRONG&gt; put(DATEOFDIAGNOSIS,&lt;FONT color="#ff0000"&gt;12.&lt;/FONT&gt;);&lt;/STRONG&gt;&lt;BR /&gt;sas_date = input (char_var, mmddyy&lt;FONT color="#008000"&gt;&lt;STRONG&gt;8&lt;/STRONG&gt;&lt;/FONT&gt;.);&lt;BR /&gt;format sas_date date8.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have &lt;STRONG&gt;8 &lt;/STRONG&gt;digits why did you put &lt;STRONG&gt;12&lt;/STRONG&gt;? That adds 4 blank spaces at the begining of the character value. The mmddyy Informat starts reading at the first position of the character value&amp;nbsp;which is blank and hence invalid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338848#M77248</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-07T15:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert numeric value to SAS date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338956#M77277</link>
      <description>&lt;P&gt;Thank you very much! Worked like a charm!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338956#M77277</guid>
      <dc:creator>sy12345</dc:creator>
      <dc:date>2017-03-07T19:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert numeric value to SAS date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338957#M77278</link>
      <description>I didn't know about that. I just saw that the format was in "BEST12." so I thought I had to match that. Thank you for the info though!</description>
      <pubDate>Tue, 07 Mar 2017 19:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-numeric-value-to-SAS-date/m-p/338957#M77278</guid>
      <dc:creator>sy12345</dc:creator>
      <dc:date>2017-03-07T19:42:57Z</dc:date>
    </item>
  </channel>
</rss>

