<?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: datetime20. format in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683311#M24159</link>
    <description>&lt;P&gt;When you create a new column in SQL through a calculation or function, it does not have a name, so you either give it one, or the SQL procedure will assign one automatically. Do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datepart(MMDD3) format=date9. as MMDD3&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 11 Sep 2020 17:09:32 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-09-11T17:09:32Z</dc:date>
    <item>
      <title>datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683307#M24158</link>
      <description>&lt;PRE&gt;/* MMDD1,2,3 are datetime20. format in tab dataset   02AUG2020:00:00:00*/
proc sql ;
create table Deposits_DetailXX as 
select 
MMDD1,
MMDD2 format=dtdate9.,
datepart(MMDD3) format=date9.
from tab;
quit;
&lt;/PRE&gt;
&lt;P&gt;tab dataset opened&lt;/P&gt;
&lt;PRE&gt;MMDD1                       MMDD2         _TEMA001
02AUG2020:00:00:00&amp;nbsp;&amp;nbsp;02AUG2020&amp;nbsp;   02AUG2020&lt;/PRE&gt;
&lt;P&gt;exported as xlsx&lt;/P&gt;
&lt;PRE&gt;MMDD1	                         MMDD2	        _TEMA001
8/2/2020  12:00:00 AM	1911945600	2-Aug-20&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;1. where is MMDD3 varible? is it&amp;nbsp; renamed to _tema001 ? why and how?&lt;/P&gt;
&lt;P&gt;2. i used somewhere this format dtdate9. got expected result. but i am not getting how to use now..&lt;/P&gt;
&lt;P&gt;3. date9. can't applied on datetime varible ,so datepart is calculated and then applied date9. and it is working fine.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 16:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683307#M24158</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-09-11T16:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683311#M24159</link>
      <description>&lt;P&gt;When you create a new column in SQL through a calculation or function, it does not have a name, so you either give it one, or the SQL procedure will assign one automatically. Do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datepart(MMDD3) format=date9. as MMDD3&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2020 17:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683311#M24159</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-11T17:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683316#M24160</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52150"&gt;@rajeshm&lt;/a&gt;&amp;nbsp;wrote:
&lt;P class="1599844703264"&gt;&amp;nbsp;&lt;/P&gt;
&lt;SPAN style="background-color: #f5f5f5; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px;"&gt;1. where is MMDD3 varible? is it&amp;nbsp; renamed to _tema001 ? why and how?&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You never named the variable so SAS assigned a default name. When you apply a transformation to a variable it's no longer the old variable, you explicitly need to give it a name. This is a SQL standard across the board.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. i used somewhere this format dtdate9. got expected result. but i am not getting how to use now..&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Formats with a DT in front are typically for DATETIME values, DT means &lt;STRONG&gt;D&lt;/STRONG&gt;ate&lt;STRONG&gt;T&lt;/STRONG&gt;ime format for a DATETIME variable. Using DATEPART converts a variable from a DATETIME to a DATE so a DATETIME variable is no longer valid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;3. date9. can't applied on datetime varible ,so datepart is calculated and then applied date9. and it is working fine.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The variable is a DATE variable now, so you can use a DATE format, not a DATETIME format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52150"&gt;@rajeshm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;/* MMDD1,2,3 are datetime20. format in tab dataset   02AUG2020:00:00:00*/
proc sql ;
create table Deposits_DetailXX as 
select 
MMDD1,
MMDD2 format=dtdate9.,
datepart(MMDD3) format=date9.
from tab;
quit;
&lt;/PRE&gt;
&lt;P&gt;tab dataset opened&lt;/P&gt;
&lt;PRE&gt;MMDD1                       MMDD2         _TEMA001
02AUG2020:00:00:00&amp;nbsp;&amp;nbsp;02AUG2020&amp;nbsp;   02AUG2020&lt;/PRE&gt;
&lt;P&gt;exported as xlsx&lt;/P&gt;
&lt;PRE&gt;MMDD1	                         MMDD2	        _TEMA001
8/2/2020  12:00:00 AM	1911945600	2-Aug-20&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;1. where is MMDD3 varible? is it&amp;nbsp; renamed to _tema001 ? why and how?&lt;/P&gt;
&lt;P&gt;2. i used somewhere this format dtdate9. got expected result. but i am not getting how to use now..&lt;/P&gt;
&lt;P&gt;3. date9. can't applied on datetime varible ,so datepart is calculated and then applied date9. and it is working fine.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 17:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683316#M24160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-11T17:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683318#M24161</link>
      <description>&lt;P&gt;mmdd2 is datetime20. informat&lt;/P&gt;
&lt;P&gt;1. I would like to get the date from that variable, so used dtdtate9. to read date from datetime20...&lt;/P&gt;
&lt;P&gt;dataset field value showing correct(dateformat). but while exporting xlsx getting big number , how to get date&amp;nbsp; in excel for mmdd2 ,please let me know&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MMDD2 format=dtdate9.,
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 17:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683318#M24161</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-09-11T17:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683321#M24162</link>
      <description>&lt;P&gt;The format you use to&amp;nbsp;&lt;EM&gt;display&lt;/EM&gt; a value&amp;nbsp;&lt;STRONG&gt;does not change&lt;/STRONG&gt; the value. When you export to Excel, it exports the &lt;EM&gt;stored&lt;/EM&gt; value.&lt;/P&gt;
&lt;P&gt;BTW in Excel, datetimes and dates are stored basically the same, because Excel stores times as fractions of a day, not as counts of seconds as SAS does.&lt;/P&gt;
&lt;P&gt;Please show your code you used to export the resulting SAS dataset to Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 18:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683321#M24162</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-11T18:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683323#M24163</link>
      <description>&lt;P&gt;If you want to get a formatted value in Excel, consider using ODS EXCEL and PROC PRINT. Or write a csv file with a DATA step, whery you set the format in the PUT statement.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 18:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683323#M24163</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-11T18:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683324#M24164</link>
      <description>&lt;PRE&gt;proc export data=xx outfile="/bbb.xlsx" dbms=xlsx replace; sheet="firstl";&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2020 18:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683324#M24164</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-09-11T18:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683325#M24165</link>
      <description>&lt;P&gt;without ods and with proc export , can i solve my issue or not?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 18:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683325#M24165</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-09-11T18:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: datetime20. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683327#M24166</link>
      <description>&lt;P&gt;Looks like PROC EXPORT is confused by the DTDATE format; I ran this on UE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
dt1 = datetime();
dt2 = dt1;
dt3 = datepart(dt1);
format
  dt1 datetime20.
  dt2 dtdate9.
  dt3 date9.
;
run;

proc export
  data=test
  file='/folders/myfolders/test.xlsx'
  dbms=xlsx
  replace
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and lo and behold! the DT2 column was exported as a raw number instead of being converted to Excel datetime (count of days from 30dec1899, time as fraction of a day).&lt;/P&gt;
&lt;P&gt;Bring this to the attention of SAS technical support.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see three workarounds:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;create a date column with DATEPART&lt;/LI&gt;
&lt;LI&gt;use the DATETIME format, and assign a pure date format in Excel after opening the file there (because the values before the decimal point are the same, but be careful because of the "invisible" time part!)&lt;/LI&gt;
&lt;LI&gt;export to a csv file; this will put the formatted values ihn the file, so Excel will see something it can read as a date&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS this was my post # 18.000 here on the communities.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 19:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/datetime20-format/m-p/683327#M24166</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-11T19:33:27Z</dc:date>
    </item>
  </channel>
</rss>

