<?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: working with date/time variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246428#M46098</link>
    <description>&lt;P&gt;Thank you for your reply! I added mmddyy9. after the twowk_sdate variable name as well (didn't try it without), and it worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jan 2016 19:37:46 GMT</pubDate>
    <dc:creator>phoenix95</dc:creator>
    <dc:date>2016-01-27T19:37:46Z</dc:date>
    <item>
      <title>working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246417#M46091</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have a question about two date/time variable in my dataset....The first is an interview start date &amp;amp; time and the second is the interview end date &amp;amp; time. When I run a&amp;nbsp;proc contents it says the informat for this variable is ANYDTDTM40. and the format is DATETIME. (the result is this: &lt;STRONG&gt;08NOV15:15:56:00&lt;/STRONG&gt;). I would like to convert this to a MMDDYY10. variable, but cannot figure it out! I have checked out other posts on similar topics but have been unsuccessful.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my datastep, I most recenlty tried created two new variables using the dates from the original variables but it's not working:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;twowk_sdate = datepart(v8);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;twowk_edate = datepart(v9);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 18:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246417#M46091</guid>
      <dc:creator>phoenix95</dc:creator>
      <dc:date>2016-01-27T18:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246418#M46092</link>
      <description>&lt;P&gt;Add the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format twowk_sdate twowk_edate mmddyy9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and you should see the dates in a recognizable format.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 18:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246418#M46092</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-27T18:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246420#M46093</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/70486"&gt;@phoenix95﻿&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;DATE = "08NOV15:15:56:00";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;NewDate = input( scan(DATE,1,':'),date9.);&lt;BR /&gt;NewTime = input (substr(DATE ,9,5),time6.);&lt;BR /&gt;format NewDate MMDDYY10. NewTime time6.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 19:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246420#M46093</guid>
      <dc:creator>samnan</dc:creator>
      <dc:date>2016-01-27T19:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246421#M46094</link>
      <description>&lt;P&gt;or you can use this (b&amp;nbsp;data _null_ and&amp;nbsp;Reeza&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;original_var = "08NOV15:15:56:00";&lt;BR /&gt;dt_var=input(original_var, datetime16.);&lt;BR /&gt;date_part=datepart(dt_var);&lt;BR /&gt;time_part=timepart(dt_var);&lt;BR /&gt;format dt_var datetime16. date_part MMDDYY10. time_part time6.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=have;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 19:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246421#M46094</guid>
      <dc:creator>samnan</dc:creator>
      <dc:date>2016-01-27T19:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246428#M46098</link>
      <description>&lt;P&gt;Thank you for your reply! I added mmddyy9. after the twowk_sdate variable name as well (didn't try it without), and it worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 19:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246428#M46098</guid>
      <dc:creator>phoenix95</dc:creator>
      <dc:date>2016-01-27T19:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246429#M46099</link>
      <description>&lt;P&gt;Hi Samnan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply! I tried what looked like the simplest solution from the first commenter and it worked. Thank you though for taking the time to reply, I greatly appreciate it!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 19:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246429#M46099</guid>
      <dc:creator>phoenix95</dc:creator>
      <dc:date>2016-01-27T19:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246459#M46114</link>
      <description>&lt;P&gt;For most purposes you don't need an additional variable, only&amp;nbsp;a different format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   x = "08NOV15:15:56:00"dt;
   put  "with long datetime format "  x= datetime. "with short " x= datetime9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jan 2016 20:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246459#M46114</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-27T20:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246472#M46118</link>
      <description>&lt;P&gt;Hi PG,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm running into another error I am hoping you can advise me on. I am trying to take the difference between 2 dates in SAS. I would like to get the number of days between an interview due date and the actual interview date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As part of my data step I am doing the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;intvwdatdiff = intck ('day', twowkintduedate, twowk_edate);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And it's coming up with a date like this 12/07/59 (all with the same year '59). Is this also a formatting issue or am I using the wrong function to take the difference between the two dates?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 21:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246472#M46118</guid>
      <dc:creator>phoenix95</dc:creator>
      <dc:date>2016-01-27T21:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246477#M46121</link>
      <description>&lt;P&gt;The number of days between two dates is not a date, and shouldn't be given a date format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;format intvwdatdiff 5.0;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 21:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246477#M46121</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-27T21:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246684#M46182</link>
      <description>&lt;P&gt;That worked! Thank you PG. If you have the time, can you explain what the formatting with the 5.0 did?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, many thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 16:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246684#M46182</guid>
      <dc:creator>phoenix95</dc:creator>
      <dc:date>2016-01-28T16:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246687#M46184</link>
      <description>&lt;P&gt;Formatting only affect the way a value is represented, it doesn't change the value itself. The 5.0 format requests that the number of days be represented as a number with zero decimals in a field of 5 characters.&lt;/P&gt;
&lt;P&gt;BTW, the strange values that you got before was because SAS uses 01JAN1960 as a reference for its internal representation of dates.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 16:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246687#M46184</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-28T16:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246697#M46189</link>
      <description>&lt;P&gt;Thank you again, this is great. My calculations seem a bit off though. I used this line in the data step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;intvwdatdiff = intck ('day', babydob, twowk_edate);&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;along with the format&amp;nbsp;&lt;SPAN&gt;intvwdatdiff 5.0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My results though show the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;intvwdatdiff = 7 for a woman with babydob of 2/24/15 and follow-up interview date of 3/6/15. When I look at a 2015 calendar &amp;nbsp;that's actually a 10 day difference, not a 7 day difference. Some of the other calculations are correct though. For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;intvwdatdiff = 10 where babydob = 2/15/15 and follow-up interview date of 2/25/15. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any idea why this is happening?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 17:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246697#M46189</guid>
      <dc:creator>phoenix95</dc:creator>
      <dc:date>2016-01-28T17:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246733#M46209</link>
      <description>&lt;P&gt;No. As far as I know, intnx gives reliable results.&lt;/P&gt;
&lt;P&gt;Going to an unambiguous date format such as yymmdd10. might help diagnose the problem.&lt;/P&gt;
&lt;P&gt;Try to create a small example where the problem shows up.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 19:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/246733#M46209</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-28T19:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/248337#M46649</link>
      <description>&lt;P&gt;Hi PG,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response! I think I figured out why my date calculations are off. In February 2015 there were only 28 days (there are 29 days in Feb this year). So the miscalculation or the difference of 3 days from what the actual calculation should have been -- must be b/c February 2015 is missing the 29th, 30th, and 31st. In other words, I wonder if the intck command assumes 31 days in a month?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2016 16:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/248337#M46649</guid>
      <dc:creator>phoenix95</dc:creator>
      <dc:date>2016-02-05T16:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: working with date/time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/248340#M46651</link>
      <description>&lt;P&gt;To my knowledge nobody ever reported a problem with the intck function. Try the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
do Year = 1995 to 2016;
    date28feb = mdy(2,28,year);
    date01mar = mdy(3,1,year);
    nbDays = intck("DAY", date28feb, date01mar);
    put (_all_) (=);
    end;
format date: yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Feb 2016 17:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/working-with-date-time-variables/m-p/248340#M46651</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-05T17:08:29Z</dc:date>
    </item>
  </channel>
</rss>

