<?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: Excel-VBA transfers incorrect date values from SAS to Excel-sheet in Microsoft Integration with SAS</title>
    <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233484#M1751</link>
    <description>You could try converting the date to a text field, but that seem similar to adding 21916 anyways.</description>
    <pubDate>Fri, 06 Nov 2015 16:53:15 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-11-06T16:53:15Z</dc:date>
    <item>
      <title>Excel-VBA transfers incorrect date values from SAS to Excel-sheet</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233462#M1746</link>
      <description>&lt;P&gt;&lt;SPAN&gt;My VBA code transfers a SAS-table to Excel-sheet via &lt;/SPAN&gt;&lt;CODE&gt;ADODB.Connection&lt;/CODE&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;CODE&gt;"SAS.LocalProvider.1"&lt;/CODE&gt;&lt;SPAN&gt;. Two SAS-columns are date in the format of &lt;/SPAN&gt;&lt;CODE&gt;YYYY-MM-DD&lt;/CODE&gt;&lt;SPAN&gt;, like &lt;/SPAN&gt;&lt;CODE&gt;2015-09-01&amp;nbsp;&lt;/CODE&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;&lt;CODE&gt;2015-09-30&lt;/CODE&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;However, in the end, I get date values in the Excel-sheet like &lt;CODE&gt;1955-08-31&lt;/CODE&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;CODE&gt;1955-09-29&lt;/CODE&gt;&lt;SPAN&gt; instead of&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;2015-09-01&lt;/CODE&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;CODE&gt;2015-09-30&lt;/CODE&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I tried a code like&amp;nbsp;below, but it didn't work. It still transfers the date as "1955-08-31". I found a SAS-documentation about this issue, but it only recommends to add&amp;nbsp;21916 to the SAS-date to get the Excel-date,&amp;nbsp;&lt;A href="http://www2.sas.com/proceedings/sugi29/068-29.pdf" target="_self"&gt;SAS-Doc&lt;/A&gt;. Is it really the only solution?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lang-vb prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="kwd"&gt;Public&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;Sub&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; SASTransfer&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;()&lt;/SPAN&gt;
  &lt;SPAN class="kwd"&gt;Dim&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; rTarget1 &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;As&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; Range&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;Set&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; rTarget1 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; Sheet2&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Range&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str"&gt;"A2"&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="kwd"&gt;Dim&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; sSasTable1 &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;As&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;String&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; sSasTable1 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; SASOutputPath &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="str"&gt;"\"&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; SASOutput1 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="str"&gt;".sas7bdat"&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN class="kwd"&gt;Dim&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; con1 &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;As&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;New&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; ADODB&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Connection ' This creates a new connection
    &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;Dim&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; rs1 &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;As&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;New&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; ADODB&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Recordset   ' This creates a new RecordSet
    con1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Provider &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt; &lt;SPAN class="str"&gt;"SAS.LocalProvider.1"    'Using the SAS.LocalProvider to transfer the SAS-table into Excel &lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
    con1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Open                        ' This opens the connection, con1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; rs1.ActiveConnection = con1      ' This describes the recordset, rs1, as the active connection set&lt;BR /&gt;    &lt;BR /&gt;    rs1.Properties("SAS Formats") = "PeriodFrom=YYMMDD10." 'This presents the format of the SAS-column "PeriodFrom"&lt;BR /&gt;                                                           ' I wrote the date format, YYMMDD10., as shown inside the SAS&lt;BR /&gt;
    rs1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Open sSasTable1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; con1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; adOpenForwardOnly&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; adLockReadOnly&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; ADODB&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;adCmdTableDirect &lt;BR /&gt;    ' The line above basically describes the SAS-table "sSasTable1" and other transfer properties
    rTarget1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;CopyFromRecordset rs1     ' This line copies the SAS-table, rs1, to the target range inside the Excel-sheet
    rs1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Close
    &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;Set&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; rs1 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;Nothing&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
    con1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;Close
    &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;Set&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; con1 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;Nothing&lt;/SPAN&gt;

&lt;SPAN class="kwd"&gt;End&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;Sub&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233462#M1746</guid>
      <dc:creator>cercig</dc:creator>
      <dc:date>2015-11-06T15:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Excel-VBA transfers incorrect date values from SAS to Excel-sheet</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233467#M1747</link>
      <description>Do you  have access to SAS? If you push the data from SAS you may not have the same issues.</description>
      <pubDate>Fri, 06 Nov 2015 16:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233467#M1747</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-06T16:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Excel-VBA transfers incorrect date values from SAS to Excel-sheet</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233468#M1748</link>
      <description>&lt;P&gt;I guess you are right, but I try to do the whole job inside the VBA, like running the SAS-code inside VBA and then tranferring the table inside VBA. One run will be enough to fix everything, it was the aim.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233468#M1748</guid>
      <dc:creator>cercig</dc:creator>
      <dc:date>2015-11-06T16:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Excel-VBA transfers incorrect date values from SAS to Excel-sheet</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233473#M1749</link>
      <description>&lt;P&gt;I tried many methods, but only the method below worked. Adding 21916 to the date inside my SAS-code. It is not perfect, it creates the SAS-table with the date as "2079-09-30", but at least it works for my "one-run" purpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lang-vb prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;data excel_export&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;;&lt;/SPAN&gt;
     &lt;SPAN class="kwd"&gt;set&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; have&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;;&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
     PeriodFrom = PeriodFrom&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;+&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;21916&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;;&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
     format PeriodFrom YYMMDD10&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.;&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
run&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233473#M1749</guid>
      <dc:creator>cercig</dc:creator>
      <dc:date>2015-11-06T16:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Excel-VBA transfers incorrect date values from SAS to Excel-sheet</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233482#M1750</link>
      <description>&lt;P&gt;I would imagine so, never seen someone try to extract data from a dataset with VBA. &amp;nbsp;SAS stores dates as number from a certain date, Excel's dates are from another date. &amp;nbsp;Hence that need to add a certain value which is the difference between those two base dates. &amp;nbsp;Out of interest, why are you trying it this way? &amp;nbsp;Why not just export the data directly from SAS, you can set formats then at that level.&lt;/P&gt;
&lt;P&gt;Alternatively, export the data from SAS as CSV, then in your Excel file, the VBA can directly load the CSV data, and send to the Worksheet, you wouldn't have this date conversion then. &amp;nbsp;I would recommend CSV as transfer format between SAS and Excel (as Excel is not a database, so doesn't work the way you think it will).&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233482#M1750</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-06T16:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Excel-VBA transfers incorrect date values from SAS to Excel-sheet</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233484#M1751</link>
      <description>You could try converting the date to a text field, but that seem similar to adding 21916 anyways.</description>
      <pubDate>Fri, 06 Nov 2015 16:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Excel-VBA-transfers-incorrect-date-values-from-SAS-to-Excel/m-p/233484#M1751</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-06T16:53:15Z</dc:date>
    </item>
  </channel>
</rss>

