<?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: date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date/m-p/609756#M177527</link>
    <description>&lt;P&gt;To convert Excel dates to SAS dates, subtract 21916.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also need the dates from Excel to show up as numeric integers, I'm not sure why that didn't happen, as you don't show your code; but I'm sure you can figure it out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to see that this works, here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    y=42933-21916;
    y1=42940-21916;
    format y y1 date7.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Dec 2019 18:08:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-12-05T18:08:00Z</dc:date>
    <item>
      <title>date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date/m-p/609733#M177518</link>
      <description>&lt;P&gt;I had TOC date in date format in excel. after imported in to SAS it became like this&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;TOC&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;After imported in SAS&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7/17/2017&lt;/TD&gt;&lt;TD&gt;42933&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7/24/2017&lt;/TD&gt;&lt;TD&gt;42940&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;After imported it is in character format, I&amp;nbsp; used this code to change it to numeric date format&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ALERTCSE.Alert_Cases_TOC;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;SET&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ALERTCSE.Alert_Cases;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Test_of_Cure &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;TOC = INPUT (TOC, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; TOC;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;rename&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Test_of_Cure=TOC;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;and it says this;&lt;/P&gt;&lt;P&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the&lt;/P&gt;&lt;P&gt;operations have been set to missing values.&lt;/P&gt;&lt;P&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/P&gt;&lt;P&gt;85 at 193:16&lt;/P&gt;&lt;P&gt;NOTE: There were 166 observations read from the data set ALERTCSE.ALERT_CASES.&lt;/P&gt;&lt;P&gt;NOTE: The data set ALERTCSE.ALERT_CASES_TOC has 166 observations and 36 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.21 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.14 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And TOC column is with these dates which is WRONG&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;TOC&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/29/1933&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/29/1940&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 16:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date/m-p/609733#M177518</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2019-12-05T16:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date/m-p/609747#M177522</link>
      <description>Please share output of the below &lt;BR /&gt;1) PROC CONTENTS DATA=ALERTCSE.Alert_Cases; RUN;&lt;BR /&gt;2) PROC PRINT DATA=ALERTCSE.Alert_Cases (OBS=10); RUN;</description>
      <pubDate>Thu, 05 Dec 2019 17:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date/m-p/609747#M177522</guid>
      <dc:creator>Shakir_Juolay</dc:creator>
      <dc:date>2019-12-05T17:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date/m-p/609756#M177527</link>
      <description>&lt;P&gt;To convert Excel dates to SAS dates, subtract 21916.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also need the dates from Excel to show up as numeric integers, I'm not sure why that didn't happen, as you don't show your code; but I'm sure you can figure it out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to see that this works, here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    y=42933-21916;
    y1=42940-21916;
    format y y1 date7.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 18:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date/m-p/609756#M177527</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-05T18:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date/m-p/609788#M177545</link>
      <description>&lt;P&gt;If you have mixed type cells (numeric and character) in the same column of your spreadsheet then SAS will define the variable as character.&amp;nbsp; For DATE values that are in that column SAS will store the value as the character representation of the number that Excel uses for dates.&amp;nbsp; To fix it make sure the Excel sheet has only one type of data in that column.&amp;nbsp; Then SAS will know it is a date and do the conversion for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you cannot fix the Excel sheet then you will have to do something in SAS.&amp;nbsp; So convert the value to a number than change the value to reflect difference in how SAS and Excel count days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes Excel gets confused by strings that look like dates to humans, but not to Excel and will store those as a character string.&lt;/P&gt;
&lt;P&gt;Here is code that will first try to convert the TOC value to a number.&amp;nbsp; If it doesn't work it will then try to convert it using a specific date informat.&amp;nbsp; If it does work then it will add the SAS date for 2 day before 1900.&amp;nbsp; SAS uses 1960 as the start and Excel uses 1900.&amp;nbsp; But they made different decisions about whether to count from zero or one and Excel mistakenly thinks 1900 was a leap year.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ALERTCSE.Alert_Cases_TOC;
  set ALERTCSE.Alert_Cases;
  format Test_of_Cure mmddyy10.;
  test_of_cure = input(toc,??32.);
  if missing(test_of_cure) and not missing(toc) then do;
      test_of_cure=input(toc,mmddyy10.);
  end;
  else do;
      test_of_cure = test_of_cure + '30DEC1899'd ;
  end;
  rename TOC=TOC_char ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 19:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date/m-p/609788#M177545</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-05T19:48:56Z</dc:date>
    </item>
  </channel>
</rss>

