<?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 Struggling with splitting up data and time in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50955#M13919</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two columns in my database, one is start date and other is end data. These two columns are formatted like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Start date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Date&lt;/P&gt;&lt;P&gt;01May2010:00:00:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 02June2010:00:00:00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to subtract the dates to find out number of days in between. I have tried formatting date and substring function but nothing worked. Whatever function I try, my date gets changed to weird numbers like 15000786 etc. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would really appreciate your time and help regarding this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Aug 2011 21:19:43 GMT</pubDate>
    <dc:creator>Nupur20</dc:creator>
    <dc:date>2011-08-18T21:19:43Z</dc:date>
    <item>
      <title>Struggling with splitting up data and time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50955#M13919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two columns in my database, one is start date and other is end data. These two columns are formatted like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Start date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Date&lt;/P&gt;&lt;P&gt;01May2010:00:00:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 02June2010:00:00:00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to subtract the dates to find out number of days in between. I have tried formatting date and substring function but nothing worked. Whatever function I try, my date gets changed to weird numbers like 15000786 etc. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would really appreciate your time and help regarding this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Aug 2011 21:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50955#M13919</guid>
      <dc:creator>Nupur20</dc:creator>
      <dc:date>2011-08-18T21:19:43Z</dc:date>
    </item>
    <item>
      <title>Struggling with splitting up data and time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50956#M13920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data P01.output_ds;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; format start end date9.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set P01.input_ds;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; start=datepart(startdate);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end=datepart(enddate);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; daysdiff=intck('day', start, end);&lt;BR /&gt;run; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Aug 2011 21:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50956#M13920</guid>
      <dc:creator>robby_beum</dc:creator>
      <dc:date>2011-08-18T21:33:16Z</dc:date>
    </item>
    <item>
      <title>Struggling with splitting up data and time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50957#M13921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think that Robby has already provided the answer you need.&amp;nbsp; However, as for the daysdiff part, you could also simply use:&lt;/P&gt;&lt;P&gt;daysdiff=end-start;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Aug 2011 22:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50957#M13921</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-18T22:10:00Z</dc:date>
    </item>
    <item>
      <title>Struggling with splitting up data and time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50958#M13922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the DATEPART extractions are needed for other purposes, go ahead with them. However, the day difference can be calculated directly from the given datetimes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier New;"&gt;daysdiff=intck(&lt;SPAN style="color: #800080;"&gt;'dtday'&lt;/SPAN&gt;, startdate, enddate) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;robby_beum wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data P01.output_ds;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; format start end date9.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set P01.input_ds;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; start=datepart(startdate);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end=datepart(enddate);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; daysdiff=intck('day', start, end);&lt;BR /&gt;run; &lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Aug 2011 00:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50958#M13922</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2011-08-19T00:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with splitting up data and time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50959#M13923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's worth noting the reason for your issue is that your values are datetimes, not dates.&amp;nbsp; Unlike other platforms SAS treats these differently and they cannot be used together (directly).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you subtract the datetimes, the difference you see is the number of seconds between the two.&amp;nbsp; When you do the same with dates you get the number of days.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In its numerical form, SAS counts dates as the number of days since 1st Jan 1960, and datetime as the number of seconds since midnight of 1st Jan 1960.&amp;nbsp; You can see this using the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;format date date9.;&lt;/P&gt;&lt;P&gt;format datetime datetime20.;&lt;/P&gt;&lt;P&gt;date = 1;&lt;/P&gt;&lt;P&gt;datetime = 1;&lt;/P&gt;&lt;P&gt;diff = '02JUN2011:00:00:00'dt - '01MAY2011:00:00:00'dt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The DatePart and TimePart functions, convert a datetime into its respective components.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: I've added the difference calculation using your sample datetimes.&amp;nbsp; The result is 2,764,800 which is the equivalent of 32 days but expressed in seconds (32*24*60*60).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: DF&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Aug 2011 11:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50959#M13923</guid>
      <dc:creator>DF</dc:creator>
      <dc:date>2011-08-19T11:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with splitting up data and time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50960#M13924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not meaning to strech this thread to absurdity, but using Iho's example, if you do the math for SAS you can trim approximately 30% off of your processing time. i.e., the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; diff=(End_date-Start_date)/(86400);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;will produce the same result and use up about 30% less cpu time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I only responded, again, because I noticed one of your example dates: 02June2010:00:00:00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is that REALLY the way your data looks or was 'June' really 'Jun'?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Aug 2011 22:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50960#M13924</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-19T22:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with splitting up data and time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50961#M13925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You so much guyz!! You are awesome.. It worked &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;I initially spent hours figuring out this..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Aug 2011 01:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Struggling-with-splitting-up-data-and-time/m-p/50961#M13925</guid>
      <dc:creator>Nupur20</dc:creator>
      <dc:date>2011-08-20T01:00:06Z</dc:date>
    </item>
  </channel>
</rss>

