<?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 datetime16 to datetime9 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-datetime16-to-datetime9/m-p/353198#M82429</link>
    <description>&lt;P&gt;Dates are stored in days and Time and DateTime are stored in seconds.&lt;/P&gt;
&lt;P&gt;You can apply a different format (DTDATE9. for example).&lt;/P&gt;
&lt;P&gt;You can convert using the DATEPART() function.&lt;/P&gt;
&lt;P&gt;Or you could read it using a different informat that ignores the time part.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data JANFEB;
  infile datalines dsd truncover;
  length dcdeathdate dcdeathdatetime 8 nationalid $24 HCVScreening $9 HCVresult $27 ;
  informat dcdeathdate date7. dcdeathdatetime datetime16.;
  format dcdeathdate date9. dcdeathdatetime datetime20.;
  input dcdeathdate @1 dcdeathdatetime nationalid HCVScreening HCVresult ;
datalines4;
19JAN17:00:00:00,01001000070,No,
10JAN17:00:00:00,01001000357,Yes,Negative
20JAN17:00:00:00,01001000402,Yes,Negative
02FEB17:00:00:00,01001000799,Yes,Negative
18FEB17:00:00:00,01001000859,No,
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Apr 2017 14:03:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-04-25T14:03:07Z</dc:date>
    <item>
      <title>Convert datetime16 to datetime9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-datetime16-to-datetime9/m-p/353173#M82423</link>
      <description>&lt;P&gt;Hello, I have a dataset that has a date variable that is in datetime16. I would like to convert it to datetime9. Not quite sure how to do this. I tried this sas code but the output jarbled the date variable to "*******"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data janfeb;
set janfeb;
  format dcdeathdate date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data JANFEB;
  infile datalines dsd truncover;
  input dcdeathdate:DATETIME16. nationalid:$24. HCVScreening:$9. HCVresult:$27.;
datalines4;
19JAN17:00:00:00,01001000070,No,
10JAN17:00:00:00,01001000357,Yes,Negative
20JAN17:00:00:00,01001000402,Yes,Negative
02FEB17:00:00:00,01001000799,Yes,Negative
18FEB17:00:00:00,01001000859,No,
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 13:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-datetime16-to-datetime9/m-p/353173#M82423</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-25T13:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime16 to datetime9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-datetime16-to-datetime9/m-p/353181#M82424</link>
      <description>&lt;P&gt;SAS datetime values are &lt;U&gt;seconds&lt;/U&gt; from 01-01-1960:00:00:00; date values are &lt;U&gt;days&lt;/U&gt; from 01-01-1960.&lt;/P&gt;
&lt;P&gt;To extract the date from a datetime value, use the datepart() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data JANFEB;
  infile datalines dsd truncover;
  input dcdeathdate:DATETIME16. nationalid:$24. HCVScreening:$9. HCVresult:$27.;
datalines4;
19JAN17:00:00:00,01001000070,No,
10JAN17:00:00:00,01001000357,Yes,Negative
20JAN17:00:00:00,01001000402,Yes,Negative
02FEB17:00:00:00,01001000799,Yes,Negative
18FEB17:00:00:00,01001000859,No,
;;;;
run;

data janfeb;
set janfeb;
dcdeathdate = datepart(dcdeathdate);
format dcdeathdate date9.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you simply assign the datetime9. format to dcdeathdate; it is then still a datetime value, but only the date is &lt;U&gt;displayed&lt;/U&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 13:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-datetime16-to-datetime9/m-p/353181#M82424</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-25T13:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert datetime16 to datetime9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-datetime16-to-datetime9/m-p/353198#M82429</link>
      <description>&lt;P&gt;Dates are stored in days and Time and DateTime are stored in seconds.&lt;/P&gt;
&lt;P&gt;You can apply a different format (DTDATE9. for example).&lt;/P&gt;
&lt;P&gt;You can convert using the DATEPART() function.&lt;/P&gt;
&lt;P&gt;Or you could read it using a different informat that ignores the time part.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data JANFEB;
  infile datalines dsd truncover;
  length dcdeathdate dcdeathdatetime 8 nationalid $24 HCVScreening $9 HCVresult $27 ;
  informat dcdeathdate date7. dcdeathdatetime datetime16.;
  format dcdeathdate date9. dcdeathdatetime datetime20.;
  input dcdeathdate @1 dcdeathdatetime nationalid HCVScreening HCVresult ;
datalines4;
19JAN17:00:00:00,01001000070,No,
10JAN17:00:00:00,01001000357,Yes,Negative
20JAN17:00:00:00,01001000402,Yes,Negative
02FEB17:00:00:00,01001000799,Yes,Negative
18FEB17:00:00:00,01001000859,No,
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 14:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-datetime16-to-datetime9/m-p/353198#M82429</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-25T14:03:07Z</dc:date>
    </item>
  </channel>
</rss>

