<?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: checking the dates with 0 rates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245536#M45837</link>
    <description>&lt;P&gt;Thank you !!! it worked, but i updated the orginal post, endtgdt criteria is update. i need to pick next record of the&amp;nbsp; rate recontinued value( i mean not a zero)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Cathy&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jan 2016 20:34:15 GMT</pubDate>
    <dc:creator>cathy_sas</dc:creator>
    <dc:date>2016-01-22T20:34:15Z</dc:date>
    <item>
      <title>checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245511#M45827</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a two dataset, in data one, for each id per reason taken stdt and endt. and on the other two dataset it has trgt date and rate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;/P&gt;
&lt;P&gt;input id reas stdt endt;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;100&amp;nbsp;&amp;nbsp; xxxx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15NOV2013&amp;nbsp;&amp;nbsp; 28NOV2015&lt;/P&gt;
&lt;P&gt;100 yyyy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26FEB2014&amp;nbsp;&amp;nbsp; 05MAR2014&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data two;&lt;/P&gt;
&lt;P&gt;input id tgtdt rate&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 30&lt;/STRONG&gt;OCT2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 01&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 04&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 06&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 08&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 11&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 13&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 15&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 18&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 20&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 22&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 25&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 27&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 29&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; 5&lt;STRONG&gt;.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;10FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;12FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;14FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;17FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;19FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;21FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;24FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;26FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 &lt;/STRONG&gt;28FEB2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 03&lt;/STRONG&gt;MAR2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 05&lt;/STRONG&gt;MAR2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 10&lt;/STRONG&gt;MAR2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;2.500&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 14&lt;/STRONG&gt;MAR2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;2.500&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 17&lt;/STRONG&gt;MAR2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;2.500&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;100 19&lt;/STRONG&gt;MAR2014&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;2.500&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;need to derive two dates, strtgtdt and endtgtdt . These date are after the stdt per each indvidaul reas and rate eq 0.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;In the above example :&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;for reas &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1)XXXX :&amp;nbsp; stdt is 15NOV2013 check the data against the two dataset tgtdt&amp;nbsp; , 18NOV2013 is the after the stdt, and aval is 0 so new variable strtgtdt is 18NOV2013 and endtdt(with Consecutive 0) upto 27NOV2013.pick the next date with aval not eq 0,&amp;nbsp; so ENDTGTDT is 29NOV2013&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;want:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reas &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stdt &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;endt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strtgtdt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; endtgtdt&lt;/P&gt;
&lt;P&gt;100&amp;nbsp;&amp;nbsp; xxxx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15NOV2013&amp;nbsp;&amp;nbsp; 28NOV2015&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;18&lt;/STRONG&gt;NOV2013 &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;29&lt;/STRONG&gt;NOV2013&lt;/P&gt;
&lt;P&gt;100 yyyy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26FEB2014&amp;nbsp;&amp;nbsp; 05MAR2014&amp;nbsp;&amp;nbsp; 28FEB2014&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; 10MAR2014&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Cathy&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 20:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245511#M45827</guid>
      <dc:creator>cathy_sas</dc:creator>
      <dc:date>2016-01-22T20:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245528#M45833</link>
      <description>&lt;P&gt;Hi Cathy,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date0;
do until(last.rate);
  set two;
  by id rate notsorted;
  if first.rate &amp;amp; rate=0 then strtgtdt=tgtdt;
end;
endtgtdt=tgtdt;
if strtgtdt&amp;gt;. then output;
drop tgtdt rate;
format strtgtdt endtgtdt date9.;
run;

proc sql;
create table want as
select x.*, strtgtdt, endtgtdt
from one x left join
(select b.*, reas
 from one a, date0 b
 where a.id=b.id &amp;amp; .&amp;lt;stdt&amp;lt;strtgtdt
 group by b.id, reas
 having strtgtdt=min(strtgtdt)) y
on x.id=y.id &amp;amp; x.reas=y.reas;
quit;

proc print data=want width=min;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'll give&amp;nbsp;explanations in a separate post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: corrected the BY statement in the data step.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 19:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245528#M45833</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-22T19:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245533#M45835</link>
      <description>&lt;P&gt;Here is a solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data two2;&lt;BR /&gt;set two;&lt;BR /&gt;by id rate notsorted;&lt;BR /&gt;if first.rate or last.rate;&lt;BR /&gt;if rate = 0;&lt;BR /&gt;count+1;&lt;BR /&gt;if count=3 then count=1;&lt;BR /&gt;lagdate=lag(tgtdt);&lt;BR /&gt;if count = 2 then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;strtgtdt=lagdate;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;endtgtdt=tgtdt;&lt;BR /&gt;end;&lt;BR /&gt;if count=2;&lt;BR /&gt;format strtgtdt endtgtdt date9.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.id,reas,stdt,endt,strtgtdt,endtgtdt&lt;BR /&gt;from one a inner join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two2 b on&lt;BR /&gt;stdt &amp;lt; strtgtdt &amp;lt; endtgtdt &amp;lt;= endt;&lt;BR /&gt;&lt;BR /&gt;proc sort data=want nodupkey;by id reas stdt endt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 20:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245533#M45835</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-22T20:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245534#M45836</link>
      <description>&lt;P&gt;For each ID,&amp;nbsp;dataset DATE0 contains one observation per block of consecutive observations in dataset TWO with RATE=0. Variables are ID, STRTGTDT (=first TGTDT in the block) and ENDTGTDT (=last TGTDT in the block). It is assumed that dataset TWO is sorted by ID. If it is also sorted by TGTDT within each ID (as is the case in your example data), the dates STRTGTDT and ENDTGTDT are not only the "first" and "last" in the respective block in terms of their position in the dataset, but also chronologically (i.e. earliest and latest).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now let's consider the PROC SQL step. The inline view with the alias y looks at groups of observations combined from datasets ONE and DATE0 with common ID and REAS and with the condition that STRTGTDT is a date after STDT. (In particular, cases with STDT=STRTGTDT would not be selected, but this could be changed easily if required.) Within these groups it selects those observations with the minimum STRTGTDT of the group. In your example data this minimum condition uniquely determines one observation in the group. If this was&amp;nbsp;not the case in your real data, we might need to insert a "DISTINCT" into the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, the primary SELECT statement in the step adds the date pair(s) of STRTGTDT and ENDTGTDT resulting from the inline view to the data from the matching observation of dataset ONE, where "matching" means having the same ID and REAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in case that there is no block in dataset TWO with RATE=0 and TGTDT after the STDT of a particular ID and REAS from dataset ONE, both STRTGTDT and ENDTGTDT will be missing. But there is no such case in your example data.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 20:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245534#M45836</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-22T20:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245536#M45837</link>
      <description>&lt;P&gt;Thank you !!! it worked, but i updated the orginal post, endtgdt criteria is update. i need to pick next record of the&amp;nbsp; rate recontinued value( i mean not a zero)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Cathy&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 20:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245536#M45837</guid>
      <dc:creator>cathy_sas</dc:creator>
      <dc:date>2016-01-22T20:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245537#M45838</link>
      <description>&lt;P&gt;Thank you So much for nice explanation!!! I modified the original post, where the endtgtdt criteria is updated!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where we need to consider the earliest date after the 0 rate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Cathy&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 20:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245537#M45838</guid>
      <dc:creator>cathy_sas</dc:creator>
      <dc:date>2016-01-22T20:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245539#M45840</link>
      <description>&lt;P&gt;I had a very similar proposal. I hope&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11453"&gt;@cathy_sas﻿&lt;/a&gt;&amp;nbsp;can adapt your code to her &lt;EM&gt;updated&lt;/EM&gt;&amp;nbsp;requirements.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 20:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245539#M45840</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-22T20:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245540#M45841</link>
      <description>&lt;P&gt;Here is my updated code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data two2;&lt;BR /&gt;set two;&lt;BR /&gt;by id rate notsorted;&lt;BR /&gt;if first.rate;&lt;BR /&gt;if rate ne 0 then count+1;&lt;BR /&gt;if rate = 0 then count=1;&lt;BR /&gt;lagdate=lag(tgtdt);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;strtgtdt=lagdate;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;endtgtdt=tgtdt;&lt;BR /&gt;format strtgtdt endtgtdt date9.;&lt;BR /&gt;if count=2;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.id,reas,stdt,endt,strtgtdt,endtgtdt&lt;BR /&gt;from one a inner join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two2 b on&lt;BR /&gt;stdt &amp;lt; strtgtdt;&lt;BR /&gt;&lt;BR /&gt;proc sort data=want nodupkey;by id reas stdt endt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 21:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245540#M45841</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-22T21:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245547#M45844</link>
      <description>&lt;P&gt;And here is &lt;EM&gt;my&lt;/EM&gt; updated code: Please replace the original data step by these two data steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date1;
set two;
by id rate notsorted;
if first.rate;
run;

data date0;
retain strtgtdt;
set date1;
by id;
if rate=0 then strtgtdt=tgtdt;
else if strtgtdt&amp;gt;. then endtgtdt=tgtdt;
if strtgtdt&amp;gt;. &amp;amp; (endtgtdt&amp;gt;. | last.id) then do;
  output;
  strtgtdt=.;
end;
drop tgtdt rate;
format strtgtdt endtgtdt date9.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jan 2016 21:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245547#M45844</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-22T21:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245552#M45846</link>
      <description>&lt;P&gt;Here is the updated explanation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset DATE1 simply contains the first observation from each block of consecutive observations in dataset TWO with identical ID and RATE values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second datastep goes through dataset DATE1. When it hits an obs. with RATE=0 it stores the TGTDT date in variable STRTGTDT. If, after STRTGTDT has been set, an obs. with RATE ne 0 is reached, the TGTDT value of this observation is written to variable ENDTGTDT. If the pair (STRTGTDT, ENDTGTDT) is complete or if the last obs. of the ID has been reached, the ID and the two date variables are written to dataset DATE0 and STRTGTDT is reset to missing. (Please note that ENDTGTDT in DATE0 can have a missing value if the last observation of the ID in dataset TWO has RATE=0.)&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 21:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245552#M45846</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-22T21:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245571#M45848</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11453"&gt;@cathy_sas﻿&lt;/a&gt;:&amp;nbsp;So, now you've got two solutions. They yield identical results with the test data you provided. However, they do &lt;STRONG&gt;not&lt;/STRONG&gt; yield identical results on &lt;EM&gt;all possible&lt;/EM&gt; input data similar to datasets ONE and TWO&amp;nbsp;one could think of, because they make different assumptions. Hence, they &lt;EM&gt;may or may not&lt;/EM&gt; yield identical results with your &lt;EM&gt;real&lt;/EM&gt; data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, I would recommend that you test the suggested solutions with more input datasets and compare the results to&amp;nbsp;your expectations.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Think of special, possibly "degenerate" cases that may occur (or in fact &lt;EM&gt;do&lt;/EM&gt; occur) in your real data.&lt;/LI&gt;
&lt;LI&gt;Avoid oversimplified test data (e.g. would it be realistic that the RATE is constant from the very first until the last obs. before it suddenly drops to 0?)&lt;/LI&gt;
&lt;LI&gt;Also, be aware of potential numeric representation issues if the &lt;SPAN&gt;RATE&lt;/SPAN&gt;s are not integers or have been calculated from non-integer values. (This means: It could happen that consecutive RATEs look as if they were identical in PROC PRINT output, even in BEST32. format, but in fact they are slightly different.)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In short, try to make your test data as realistic as possible.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 23:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245571#M45848</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-22T23:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245588#M45851</link>
      <description>&lt;P&gt;Thank you for your brief explanation!!! it is really a good learning curve!!!! Yes i agreed with you my real data is more complicated than the sample data which i have it here. but definately your sample code is starting point... i am working and need to see more in to the data, any issues causing to get wrong values!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a small question , if i want to create a 2 variable prevrate and prvdt&amp;nbsp;&amp;nbsp; stdt &amp;lt; tgtdt&amp;nbsp; , assign tgtdt &amp;amp; correcpoding rate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;d&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reas &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stdt &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;endt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strtgtdt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; endtgtdt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prvdt&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; prevrate&lt;/P&gt;
&lt;P&gt;100&amp;nbsp;&amp;nbsp; xxxx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15NOV2013&amp;nbsp;&amp;nbsp; 28NOV2015&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;18&lt;/STRONG&gt;NOV2013 &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;29&lt;/STRONG&gt;NOV2013&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;15&lt;/STRONG&gt;NOV2013&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;100 yyyy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26FEB2014&amp;nbsp;&amp;nbsp; 05MAR2014&amp;nbsp;&amp;nbsp; 28FEB2014&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; 10MAR2014&amp;nbsp;&amp;nbsp; 26FEB2014&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;5.000&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thanks&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;cathy&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 00:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245588#M45851</guid>
      <dc:creator>cathy_sas</dc:creator>
      <dc:date>2016-01-23T00:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245628#M45861</link>
      <description>&lt;P&gt;Hi Cathy,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have prepared code that incorporates your "small question."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The extended specifications were a good opportunity for me to redesign the data step that prepares the second input dataset for the pivotal PROC SQL step.&amp;nbsp;It is now more flexible in view of possible future requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not quite sure if I interpreted your new sample result data and the pertinent description "create a 2 variable prevrate and prvdt stdt &amp;lt; tgtdt , assign tgtdt &amp;amp; correcpoding rate" correctly.&amp;nbsp;This is because I don't see where the inequality "stdt &amp;lt; tgtdt" fits in there. In the example we have stdt=prvdt in both observations, but this might be coincidence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please elaborate on this point if you think that the new solution suggested below does not account for it.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the new code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Aggregate information from each block of obs. (per ID) with constant RATE */

data blocks;
do until(last.rate);
  set two;
  by id rate notsorted;
  if first.rate then date1=tgtdt;
end;
datelast=tgtdt;
drop tgtdt;
format date: date9.;
run;

/* Focus on blocks with RATE=0 and add information from previous and next block */

data blocks0(drop=obsno rate);
set blocks;
by id;
obsno+1;
if rate=0 then do;
  pnt=obsno-1;
  if ~first.id then set blocks(rename=(date1    = prevdate1
                                       datelast = prevdatelast
                                       rate     = prevrate)) point=pnt;
  else call missing(of prev:);
  pnt=obsno+1;
  if ~last.id  then set blocks(rename=(date1    = nextdate1
                                       datelast = nextdatelast
                                       rate     = nextrate)) point=pnt;
  else call missing(of next:);
  output;
end;
drop datelast prevdate1 nextdatelast nextrate; /* not needed now, but perhaps with future specs */
run;

/* Create and show the desired output dataset */

proc sql;
create table want as
select x.*, strtgtdt, endtgtdt, prvdt, prevrate format=8.3
from one x left join
(select b.*, reas
 from one a, blocks0(rename=(date1=strtgtdt nextdate1=endtgtdt prevdatelast=prvdt)) b
 where a.id=b.id &amp;amp; .&amp;lt;stdt&amp;lt;strtgtdt
 group by b.id, reas
 having strtgtdt=min(strtgtdt)) y
on x.id=y.id &amp;amp; x.reas=y.reas;
quit;

proc print data=want width=min;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Explanations will follow soon.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 14:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245628#M45861</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-23T14:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: checking the dates with 0 rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245629#M45862</link>
      <description>&lt;P&gt;&lt;U&gt;Explanation of revised code and datasets&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of the previous datasets DATE1 and DATE0, we have now more versatile datasets BLOCKS and BLOCKS0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each ID, dataset BLOCKS contains one observation per block of consecutive observations in dataset TWO with the same RATE (be it 0 or not).&amp;nbsp;Variables are ID, RATE, DATE1 (=first TGTDT in the block) and DATELAST (=last TGTDT in the block). So, it's similar to the first version of the old dataset DATE0, but, unlike DATE0, it is not restricted to blocks with RATE=0.&amp;nbsp;The reason is that we need information from blocks with RATE not equal to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In contrast, dataset BLOCKS0 is restricted to blocks with RATE=0 (hence its name) and has again one obs. per block.&amp;nbsp;It is created by the second data step, which reads the observations from dataset BLOCKS with RATE=0 and the previous and the following obs. of each of these observations. The look-back and look-ahead techniques used are the same: second SET statement with POINT= option.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;As a result, BLOCKS0 contains the ID and DATE1 ("first date") values from each block (in dataset TWO) with RATE=0 and, in addition,&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the values RATE and DATELAST (see description of BLOCKS above) from the preceding block&amp;nbsp;(i.e. with RATE ne 0)&lt;/LI&gt;
&lt;LI&gt;the value DATE1 from the following block (again, necessarily&amp;nbsp;with RATE ne 0).&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I think, the names of these three additional variables are self-explanatory: PREVRATE, PREVDATELAST and NEXTDATE1.&amp;nbsp;Please note that the second data step creates even more variables: PREVDATE1, NEXTDATELAST and NEXTRATE.&amp;nbsp;But these three are dropped at the end, as is DATELAST from the "zero rate observation", because they are not needed in your current requirements.&amp;nbsp;Obviously, we could make these pieces of information (first date of previous block, last date and rate of next block, last date of current block) available immediately, if needed in future specifications.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, I've made sure that "previous" and "following" blocks are only regarded within the same ID.&amp;nbsp;This means, if the very first block of an ID had RATE=0, the PREVxxxx variables would have missing values. Similarly, the NEXTxxxx variables of a "zero rate" block would have missing values, if this was the last block of the respective ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only minor changes were required for the final PROC SQL step: It now retrieves data from dataset BLOCKS0 rather than DATE0.&amp;nbsp;The RENAME= option used provides flexibility with regard to the names of the new variables. Three variables from BLOCKS0 are renamed to match your specifications. The fourth new variable, PREVRATE, can keep its original name. The formatting of the latter with three decimals (using format 8.3) is, of course, optional and was just suggested by your sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, please test the solution with more sample (or real) data.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 15:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-the-dates-with-0-rates/m-p/245629#M45862</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-23T15:03:39Z</dc:date>
    </item>
  </channel>
</rss>

