<?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: Problem with time() function in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22394#M88</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The simpler way is to use &lt;/P&gt;&lt;P&gt;t0 = time(); /* overwrite t0; we don't need the original value */&lt;/P&gt;&lt;P&gt;/* Step 2 computation */&lt;/P&gt;&lt;P&gt;t2 = time()-t0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;I think your computation is equivalent, so it must be that your jobs are crossing midnight.&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so, use DATETIME instead of TIME:&lt;/P&gt;&lt;P&gt;d0=datetime();&lt;/P&gt;&lt;P&gt;/* long computation */ &lt;/P&gt;&lt;P&gt;d1=datetime()-d0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps the more relevant question is, "Why is your computation taking so long?"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Oct 2011 12:17:00 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2011-10-03T12:17:00Z</dc:date>
    <item>
      <title>Problem with time() function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22393#M87</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a problem with the time() function. My code looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC IML;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t0 = time();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; height: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Step 1 computation */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1 = time() - t0; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; height: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Step 2 computation */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2 = (time() - t0)-t1; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg = "Step 1: _x seconds&amp;nbsp;&amp;nbsp; Step 2: _y seconds";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sX = putn(t1, "BEST5.");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sY = putn(t2, "BESTD9.");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg = tranwrd(msg, "_x", sX);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg = tranwrd(msg, "_y", sY);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRINT msg[label="Time evaluation"];&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The time for step 1 is shown correctly but step 2 usually is not. I get all sorts of numbers for t2 including negative ones.&amp;nbsp; I suppose the problem is that step 2 takes considerably longer than step 1 (20 to 30 hours for step 2, &amp;lt;1 hour for step 1). Is the time function unable to handle such long timeframes or could it be that I just don’t get the format in the putn function right? I tried several BESTxx.x&lt;SPAN style="color: #000000; background-color: white; font-size: 10pt;"&gt; values but none seemed to work. The code works fine for 2 quick computations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Many thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Oct 2011 12:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22393#M87</guid>
      <dc:creator>TomTom</dc:creator>
      <dc:date>2011-10-03T12:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with time() function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22394#M88</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The simpler way is to use &lt;/P&gt;&lt;P&gt;t0 = time(); /* overwrite t0; we don't need the original value */&lt;/P&gt;&lt;P&gt;/* Step 2 computation */&lt;/P&gt;&lt;P&gt;t2 = time()-t0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;I think your computation is equivalent, so it must be that your jobs are crossing midnight.&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so, use DATETIME instead of TIME:&lt;/P&gt;&lt;P&gt;d0=datetime();&lt;/P&gt;&lt;P&gt;/* long computation */ &lt;/P&gt;&lt;P&gt;d1=datetime()-d0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps the more relevant question is, "Why is your computation taking so long?"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Oct 2011 12:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22394#M88</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2011-10-03T12:17:00Z</dc:date>
    </item>
    <item>
      <title>Problem with time() function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22395#M89</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rick, thanks for your swift reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you saying that i should put &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t0 = time(); /* overwrite t0; we don't need the original value */&lt;/P&gt;&lt;P&gt;immediately before the step 2 computation?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To be honest, I fail to see the difference between your t2 and mine.&lt;/P&gt;&lt;P&gt;In my code t2 = (time() - t0) is an elapsed time, like in yours, but it is the time from start to finish of the whole programme. From this I am &lt;SPAN style="font-family: 'Calibri','sans-serif'; font-size: 11pt;"&gt;subtracting&lt;/SPAN&gt; the elapsed time for the first step. Can I not use elapsed times in calculations? I'd greatly appreciate it if you could elaborate.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Oct 2011 12:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22395#M89</guid>
      <dc:creator>TomTom</dc:creator>
      <dc:date>2011-10-03T12:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with time() function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22396#M90</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think what Rick is saying is that time() is just a 24 hour clock value, and doesn't handle the clock advancing to the next day, hence your getting negative values.&amp;nbsp; The datetime() function does include date and time together so it should give you the corrrect result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, if your job started at 8pm and finished next day at 7pm, you want 23 hours, but time of 8pm minus time of 7pm, to SAS, is -1 hours, i.e., 1 hour before.&amp;nbsp; TIme() has no notion of days.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Oct 2011 14:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22396#M90</guid>
      <dc:creator>DLing</dc:creator>
      <dc:date>2011-10-03T14:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with time() function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22397#M91</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm, I missed the second part of Rick's answer. Sorry about that. Actually, I was replying to the notification email I received for his post and the reply in there looks a bit different (i.e. doesn't contain the datetime bit). I'll try the datetime() function - thanks! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To answer the question why the computation takes so long: I am running what I would call a fairly complex Monte-Carlo simulation. By the way, thanks for implementing the submit statement allowing me to call procedures from within IML. I am using it for these simulations and it makes my life so much easier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Oct 2011 20:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Problem-with-time-function/m-p/22397#M91</guid>
      <dc:creator>TomTom</dc:creator>
      <dc:date>2011-10-03T20:12:00Z</dc:date>
    </item>
  </channel>
</rss>

