<?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: Difference between any two dates greater then 30 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542599#M7583</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; Thank you so much!!!! It works like a charm!!!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But is it looping inside the data step!!! Even though it works well, I still did not get the logic as to how is it working.? Please excuse me if I am asking a very basic doubt.&lt;BR /&gt;&lt;BR /&gt;Like if _n_=1, it means the 1st row correct?&lt;BR /&gt;like if _n_=1, then put that row a output and put k=dts&lt;BR /&gt;&lt;BR /&gt;Am I correct?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How is dts going to the next value is what I don't understand.&lt;BR /&gt;&lt;BR /&gt;Is this almost equal to looping?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Mar 2019 22:54:45 GMT</pubDate>
    <dc:creator>hvempati</dc:creator>
    <dc:date>2019-03-12T22:54:45Z</dc:date>
    <item>
      <title>Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542579#M7578</link>
      <description>&lt;P&gt;&lt;BR /&gt;I need to get all the dates where the difference between the previous dates is 30.&lt;/P&gt;&lt;P&gt;ex.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data cards;&lt;BR /&gt;input id dts date9.;&lt;BR /&gt;format dts date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 02JAN2017&lt;BR /&gt;2 07JAN2017&lt;BR /&gt;3 14JAN2017&lt;BR /&gt;4 21JAN2017&lt;BR /&gt;5 28JAN2017&lt;BR /&gt;6 04FEB2017&lt;BR /&gt;7 14FEB2017&lt;BR /&gt;8 31MAR2017&lt;BR /&gt;9 01APR2017&lt;BR /&gt;10 03JUN2017&lt;BR /&gt;11 10JUN2017&lt;BR /&gt;12 01JUL2017&lt;BR /&gt;13 08JUL2017&lt;BR /&gt;14 23NOV2017&lt;BR /&gt;15 14MAR2018&lt;BR /&gt;16 02APR2018&lt;BR /&gt;17 02MAY2018&lt;BR /&gt;18 05MAY2018&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;with the code below&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set WORK.cards;&lt;BR /&gt;days_between = intck('days',dts,lag(dts));&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I can get the difference with the previous date and can filter if it is less than 30.(since the days_between are -ve)&lt;/P&gt;&lt;P&gt;But my desired output should be all dates with greater than 30 days. i.e&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;dts&lt;BR /&gt;02Jan2017&lt;BR /&gt;04Feb2017&lt;BR /&gt;31Mar2017&lt;BR /&gt;03Jun2017&lt;BR /&gt;08Jul2017&lt;BR /&gt;23Nov2017&lt;BR /&gt;14Mar2018&lt;BR /&gt;02May2018&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;So basically the count resets to 0 after it finds a date. I can do this easily with loops in Python. I am not sure as how to do it in SAS.&lt;/P&gt;&lt;P&gt;Any help is highly Appreciated&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 21:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542579#M7578</guid>
      <dc:creator>hvempati</dc:creator>
      <dc:date>2019-03-12T21:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542589#M7579</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220513"&gt;@hvempati&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can get the difference with the previous date and can filter if it is less than 30.(since the days_between are -ve)&lt;/P&gt;
&lt;P&gt;But my desired output should be all dates with greater than 30 days. i.e&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What a shame you don't show your code for this part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if days_between &amp;gt;= -30 then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to get the cases where it is less than or equal to 30 days, then the code to get cases where it is more than 30 days is ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if days_between &amp;lt; -30 then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 22:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542589#M7579</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-12T22:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542593#M7580</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input id dts date9.;
format dts date9.;
datalines;
1 02JAN2017
2 07JAN2017
3 14JAN2017
4 21JAN2017
5 28JAN2017
6 04FEB2017
7 14FEB2017
8 31MAR2017
9 01APR2017
10 03JUN2017
11 10JUN2017
12 01JUL2017
13 08JUL2017
14 23NOV2017
15 14MAR2018
16 02APR2018
17 02MAY2018
18 05MAY2018
;
run;


proc sql;
create table temp as
select min(dts) as min, max(dts) as max
from have;
quit;

data want;
if _n_=1 then do;
if 0 then set have;
  dcl hash H (dataset:'have',ordered: "A") ;
   h.definekey  ("dts") ;
   h.definedata ("dts") ;
   h.definedone () ;
   dcl hiter hi('h');
end;
set temp;
dts=min;
output;
do while(hi.next()=0);
if min&amp;gt;max then leave;
if intck('days',min,dts)&amp;gt;30 then do;
output;
min=dts;
end;
end;
keep dts;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 22:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542593#M7580</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-12T22:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542595#M7581</link>
      <description>&lt;P&gt;sorry If it was not clear but&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;data want;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set WORK.cards;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;days_between = intck('days',dts,lag(dts));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is the code that gives the value&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 22:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542595#M7581</guid>
      <dc:creator>hvempati</dc:creator>
      <dc:date>2019-03-12T22:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542597#M7582</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220513"&gt;@hvempati&lt;/a&gt;&amp;nbsp; Please ignore my Hash. I feel silly and stupid to have posted that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here you go&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input id dts date9.;
format dts date9.;
datalines;
1 02JAN2017
2 07JAN2017
3 14JAN2017
4 21JAN2017
5 28JAN2017
6 04FEB2017
7 14FEB2017
8 31MAR2017
9 01APR2017
10 03JUN2017
11 10JUN2017
12 01JUL2017
13 08JUL2017
14 23NOV2017
15 14MAR2018
16 02APR2018
17 02MAY2018
18 05MAY2018
;
run;


data want;
set have;
retain k;
if _n_=1 then do;output;k=dts;end;
else if intck('days',k,dts)&amp;gt;30 then do;
output;
k=dts;
end;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Mar 2019 22:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542597#M7582</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-12T22:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542599#M7583</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; Thank you so much!!!! It works like a charm!!!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But is it looping inside the data step!!! Even though it works well, I still did not get the logic as to how is it working.? Please excuse me if I am asking a very basic doubt.&lt;BR /&gt;&lt;BR /&gt;Like if _n_=1, it means the 1st row correct?&lt;BR /&gt;like if _n_=1, then put that row a output and put k=dts&lt;BR /&gt;&lt;BR /&gt;Am I correct?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How is dts going to the next value is what I don't understand.&lt;BR /&gt;&lt;BR /&gt;Is this almost equal to looping?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 22:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542599#M7583</guid>
      <dc:creator>hvempati</dc:creator>
      <dc:date>2019-03-12T22:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542600#M7584</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220513"&gt;@hvempati&lt;/a&gt;&amp;nbsp; Your understanding is indeed correct. I see that your python mastery is putting into effect here with your quick grasp of SAS. I envy you. Have a good one!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 22:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542600#M7584</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-12T22:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542602#M7585</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220513"&gt;@hvempati&lt;/a&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;&lt;EM&gt;&lt;STRONG&gt;How is dts going to the next value is what I don't understand.?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am basically resetting the current date value as initial value once a difference of &amp;gt;30 is found&amp;nbsp; and repeat across observations.&amp;nbsp; It's no biggie.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am still &lt;U&gt;&lt;STRONG&gt;embarrassed&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;about my stupid first post. I am sure that would have given everyone at-least&amp;nbsp;a chuckle on our community. I need Valium. lol&amp;nbsp; Anyways, it's one of those days.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 23:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542602#M7585</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-12T23:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between any two dates greater then 30</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542603#M7586</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; I know you have a very high standards set for yourself. But because of that, Novice SAS user can learn a bit more about hash function. I am in fact glad that you had posted for me to learn how it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 23:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Difference-between-any-two-dates-greater-then-30/m-p/542603#M7586</guid>
      <dc:creator>hvempati</dc:creator>
      <dc:date>2019-03-12T23:08:04Z</dc:date>
    </item>
  </channel>
</rss>

