<?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: Calculate Days different in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369476#M88215</link>
    <description>&lt;P&gt;Thank you , it works.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 13:42:12 GMT</pubDate>
    <dc:creator>JHE</dc:creator>
    <dc:date>2017-06-22T13:42:12Z</dc:date>
    <item>
      <title>Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369470#M88211</link>
      <description>&lt;P&gt;I ahve two dates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Date1=&amp;nbsp; 06JUN2017:00:00:00.000,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Date=&amp;nbsp;&amp;nbsp;&amp;nbsp;12JUN2017:00:00:00.000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need calculate days between:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;intck(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'DAY'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Date1, Date2) format=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;comma10.&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TAT,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;No result, it is . &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Please advise.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Thank you&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369470#M88211</guid>
      <dc:creator>JHE</dc:creator>
      <dc:date>2017-06-22T13:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369472#M88212</link>
      <description>&lt;P&gt;Those are datetime variables. Try:&lt;/P&gt;
&lt;PRE&gt;intck('DAY', datepart(Date1), datepart(Date2)) format=comma10. AS TAT,&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369472#M88212</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-22T13:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369473#M88213</link>
      <description>&lt;P&gt;The variables you have listed are datetime variables, not dates. You can do like this do extract the date part and calculate the number of days between them&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	DateTime1=  '06JUN2017:00:00:00.000'dt;
    	DateTime2=  '12JUN2017:00:00:00.000'dt;

	Date1 = datepart(DateTime1);
	Date2 = datepart(DateTime2);

	daysbetween = intck('day', Date1, Date2);

	put daysbetween;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369473#M88213</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-06-22T13:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369474#M88214</link>
      <description>&lt;P&gt;Thank you it works.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369474#M88214</guid>
      <dc:creator>JHE</dc:creator>
      <dc:date>2017-06-22T13:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369476#M88215</link>
      <description>&lt;P&gt;Thank you , it works.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369476#M88215</guid>
      <dc:creator>JHE</dc:creator>
      <dc:date>2017-06-22T13:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369478#M88216</link>
      <description>&lt;P&gt;Just to add to the already great info, you don't actually need to ue intck at all as dates are days since 01jan1960, so you can simply do:&lt;/P&gt;
&lt;PRE&gt;datepart(date2) - datepart(date1)&lt;/PRE&gt;
&lt;P&gt;The Subtraction should be quicker than the function call.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369478#M88216</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-22T13:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369508#M88226</link>
      <description>&lt;P&gt;And yet another:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt; dif = intck(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'dtday'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,date1,date2);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;most of the date intervals will work for datetimes when prefixed with DT.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369508#M88226</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-22T14:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369527#M88238</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;: Yes, that will work, and requires less code than including the datepart function, but doesn't run much faster than using the datepart function. Conversely, like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;suggested, just doing&amp;nbsp;the subtraction is faster than either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, faster yet would be to leave the datepart function out all together (i.e., (date2-date1)/86400):&lt;/P&gt;
&lt;PRE&gt; 62         data have (drop=i);
 63           Date1=  '06JUN2017:00:00:00.000'dt;
 64           Date2=  '12JUN2017:00:00:00.000'dt;
 65           do i=1 to 10000000;
 66             output;
 67           end;
 68         run;
 
 NOTE: The data set WORK.HAVE has 10000000 observations and 2 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.73 seconds
       cpu time            0.29 seconds
       
 
 69         
 70         proc sql noprint;
 71           create table want1 as
 72             select intck('DAY', datepart(Date1), datepart(Date2)) format=comma10. AS TAT
 73              from have
 74           ;
 NOTE: Table WORK.WANT1 created, with 10000000 rows and 1 columns.
 
 75         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           1.96 seconds
       cpu time            1.95 seconds
       
 
 76         
 77         proc sql noprint;
 78           create table want2 as
 79             select datepart(Date2)-datepart(Date1) format=comma10. AS TAT
 80              from have
 81           ;
 NOTE: Table WORK.WANT2 created, with 10000000 rows and 1 columns.
 
 82         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           1.23 seconds
       cpu time            1.14 seconds
       
 
 83         
 84         proc sql noprint;
 85           create table want3 as
 86             select (Date2-Date1)/86400 format=comma10. AS TAT
 87              from have
 88           ;
 NOTE: Table WORK.WANT3 created, with 10000000 rows and 1 columns.
 
 89         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.88 seconds
       cpu time            0.87 seconds
       
 
 90         
 91         proc sql noprint;
 92           create table want4 as
 93             select intck('DTDAY', Date1, Date2) format=comma10. AS TAT
 94              from have
 95           ;
 NOTE: Table WORK.WANT4 created, with 10000000 rows and 1 columns.
 
 96         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           2.11 seconds
       cpu time            1.79 seconds&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369527#M88238</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-22T14:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369534#M88240</link>
      <description>&lt;P&gt;Yes, will consider the performance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a another wired issue, related.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mnth=19JUN2017:00:00:00.000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Work.test1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Mnth &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;mmyys10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Mnth=datepart(Mnth);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Create Table&amp;nbsp;TestA &amp;nbsp;as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select &lt;FONT face="Courier New"&gt;Mnth&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; from test1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;QUIT&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;Print data= TestA;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/2017&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;But as soon as I Join table test1 with any other tables, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;Print data=TestA&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;result would be as this : 01/1753&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;WHy this happend, how stranged ? &lt;/FONT&gt;&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>Thu, 22 Jun 2017 14:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369534#M88240</guid>
      <dc:creator>JHE</dc:creator>
      <dc:date>2017-06-22T14:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369537#M88243</link>
      <description>&lt;P&gt;We would likely need to see data from both sets including existing formats and such.&lt;/P&gt;
&lt;P&gt;My initial guess would be mixing opertions between a date value, MNTH, and a datetime value somewhere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 15:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369537#M88243</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-22T15:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Days different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369550#M88248</link>
      <description>&lt;P&gt;Since you used proc sql:, rather than proc sql;, my guess is that your code simply didn't run. The following worked for me:&lt;/P&gt;
&lt;PRE&gt;data test1;
  Mnth='19JUN2017:00:00:00.000'dt;
run;
 
data Work.test1;
  set test1;
  format Mnth mmyys10.;
  Mnth=datepart(Mnth);
run;

PROC SQL;
   Create Table TestA  as
    Select Mnth
      from test1
  ;
QUIT;

proc sql;
  create table want as
    select *
      from sashelp.class, TestA
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 15:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Days-different/m-p/369550#M88248</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-22T15:14:11Z</dc:date>
    </item>
  </channel>
</rss>

