<?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 range in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46433#M12375</link>
    <description>If you have SAS 9.2, here is a multidata hash object solution that does not require sorting.  However, the code is a little messy.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
input ID ADATE MMDDYY10. SERVICE $;&lt;BR /&gt;
format adate date7.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009  I&lt;BR /&gt;
2 1/12/2009  I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/4/2009  OP&lt;BR /&gt;
3 6/5/2009  OP&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data want(keep=id adate service);&lt;BR /&gt;
	if _n_=1 then do;&lt;BR /&gt;
		declare hash h(dataset:'have(keep=id adate rename=(adate=date))', multidata: 'y');&lt;BR /&gt;
		h.defineKey('id');&lt;BR /&gt;
		h.defineData('id', 'date');&lt;BR /&gt;
		h.definedone();&lt;BR /&gt;
	end;&lt;BR /&gt;
	set have;&lt;BR /&gt;
	foundself = 0;&lt;BR /&gt;
	if service ne 'I' then do;&lt;BR /&gt;
		h.find();&lt;BR /&gt;
		if adate = date and foundself = 0 then foundself = 1;&lt;BR /&gt;
		else if (adate = date and foundself = 1) or date = adate-1 then service = 'I';  &lt;BR /&gt;
		h.has_next(result: r);&lt;BR /&gt;
		do while(service ne 'I' and r ne 0);&lt;BR /&gt;
			h.find_next();&lt;BR /&gt;
			if adate = date and foundself = 0 then foundself = 1;&lt;BR /&gt;
			else if (adate = date and foundself = 1) or date = adate-1 then service = 'I';  &lt;BR /&gt;
			h.has_next(result: r);&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]

Message was edited by: polingjw</description>
    <pubDate>Wed, 08 Dec 2010 15:20:17 GMT</pubDate>
    <dc:creator>polingjw</dc:creator>
    <dc:date>2010-12-08T15:20:17Z</dc:date>
    <item>
      <title>checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46428#M12370</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset which has an ID, ADATE and SERVICE.&lt;BR /&gt;
&lt;BR /&gt;
ID ADATE      SERVICE&lt;BR /&gt;
&lt;BR /&gt;
1  12/7/2009     I&lt;BR /&gt;
2  1/12/2009     I&lt;BR /&gt;
2  1/13/2009     OP&lt;BR /&gt;
3  6/5/2009       I&lt;BR /&gt;
4  7/29/2009    LA&lt;BR /&gt;
5  3/23/2009    OP &lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
Now I need to check the Service that are not 'I'.  Once I find out which are the records that are not equal to 'I', I need to find out if there are any records for the same id which has the same date or 1 day earlier to that day.  If yes, then I need to convert the SERVICE from OP to 'I', else do not change the SERVICE value. &lt;BR /&gt;
&lt;BR /&gt;
Since I have a fairly huge dataset, I do not have the luxury of performing multiple iterations.  So I'm looking at doing this in minimal number of iterations.&lt;BR /&gt;
&lt;BR /&gt;
Please help.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Sandhya.</description>
      <pubDate>Tue, 07 Dec 2010 19:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46428#M12370</guid>
      <dc:creator>Sandhya</dc:creator>
      <dc:date>2010-12-07T19:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46429#M12371</link>
      <description>If you sort &lt;BR /&gt;
[pre] by id descending adate;[/pre]&lt;BR /&gt;
you can check a the service if not 1 then the next obs is the one to check for your date range.  For this DATA step approach you will need to use either a LAG function or a RETAIN.</description>
      <pubDate>Tue, 07 Dec 2010 19:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46429#M12371</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-12-07T19:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46430#M12372</link>
      <description>Hello AtrC,&lt;BR /&gt;
&lt;BR /&gt;
The OP mentioned that besides 1 day earlier date the same date is also possible. In thsi case the algorithm should be more complicated.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 07 Dec 2010 19:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46430#M12372</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-12-07T19:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46431#M12373</link>
      <description>Hello Sandhya,&lt;BR /&gt;
&lt;BR /&gt;
If I understood you correctly then this is solution (not simple one):&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i;&lt;BR /&gt;
input ID ADATE MMDDYY10. SERVICE $;&lt;BR /&gt;
format adate date7.;&lt;BR /&gt;
date=adate;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009  I&lt;BR /&gt;
2 1/12/2009  I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/4/2009  OP&lt;BR /&gt;
3 6/5/2009  OP&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=i out=s;&lt;BR /&gt;
  by ID adate;&lt;BR /&gt;
run;&lt;BR /&gt;
proc SQL noprint;&lt;BR /&gt;
  select COUNT(distinct ID) into :n from i;&lt;BR /&gt;
  %let n=%TRIM(&amp;amp;n);&lt;BR /&gt;
  select distinct ID into :id1-:id&amp;amp;n from i;&lt;BR /&gt;
quit;&lt;BR /&gt;
%macro a;&lt;BR /&gt;
%local i j k k1;&lt;BR /&gt;
%do i=1 %to &amp;amp;n;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select count(*) into :nd from s where ID=&amp;amp;&amp;amp;ID&amp;amp;i;&lt;BR /&gt;
  %let nd=%TRIM(&amp;amp;nd);&lt;BR /&gt;
  select date into :d1-:d&amp;amp;n from s where ID=&amp;amp;&amp;amp;ID&amp;amp;i;&lt;BR /&gt;
  select service into :s1-:s&amp;amp;n from s where ID=&amp;amp;&amp;amp;ID&amp;amp;i;&lt;BR /&gt;
quit;&lt;BR /&gt;
data dr&amp;amp;i;&lt;BR /&gt;
  length service $2;&lt;BR /&gt;
  %do j=1 %to &amp;amp;nd; &lt;BR /&gt;
    %if &amp;amp;&amp;amp;s&amp;amp;j NE I %then %do; &lt;BR /&gt;
      %do k=&amp;amp;j %to 1 %by -1;&lt;BR /&gt;
        %if &amp;amp;k GT 1 %then %do;&lt;BR /&gt;
          if &amp;amp;&amp;amp;d&amp;amp;j = &amp;amp;&amp;amp;d&amp;amp;k OR %EVAL(&amp;amp;&amp;amp;d&amp;amp;j - &amp;amp;&amp;amp;d&amp;amp;k) = 1 &lt;BR /&gt;
          then %let s&amp;amp;j=I;&lt;BR /&gt;
        %end;&lt;BR /&gt;
      %end;&lt;BR /&gt;
    %end; &lt;BR /&gt;
    id=&amp;amp;&amp;amp;ID&amp;amp;i;&lt;BR /&gt;
    adate=&amp;amp;&amp;amp;d&amp;amp;j;&lt;BR /&gt;
    service="&amp;amp;&amp;amp;s&amp;amp;j";&lt;BR /&gt;
    format adate date7.;&lt;BR /&gt;
    output;&lt;BR /&gt;
  %end;&lt;BR /&gt;
  run;&lt;BR /&gt;
%if &amp;amp;i = 1 %then %do; data r; retain id adate service; set dr&amp;amp;i; run; %end;&lt;BR /&gt;
%else            %do; data r; set r dr&amp;amp;i; run; %end;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend a;&lt;BR /&gt;
%a;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 07 Dec 2010 22:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46431#M12373</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-12-07T22:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46432#M12374</link>
      <description>If the data set is large, I doubt that a macro solution will be efficient.  Does this solution, which still assumes the data set is sorted by ID and ADATE, work?&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
input ID ADATE MMDDYY10. SERVICE $;&lt;BR /&gt;
format adate date7.;&lt;BR /&gt;
date=adate;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009  I&lt;BR /&gt;
2 1/12/2009  I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/4/2009  OP&lt;BR /&gt;
3 6/5/2009  OP&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=have;&lt;BR /&gt;
  by ID adate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want(keep=id adate service);&lt;BR /&gt;
	set have;&lt;BR /&gt;
	by id;&lt;BR /&gt;
	lastdate = lag(adate);&lt;BR /&gt;
	if not last then&lt;BR /&gt;
	set have(firstobs=2 keep=adate rename=(adate=nextdate)) end=last; &lt;BR /&gt;
	if service ne 'I' and ((not last.id and nextdate=adate) or (not first.id and adate-lastdate in (0 1))) then service = 'I';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[pre]</description>
      <pubDate>Wed, 08 Dec 2010 14:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46432#M12374</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2010-12-08T14:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46433#M12375</link>
      <description>If you have SAS 9.2, here is a multidata hash object solution that does not require sorting.  However, the code is a little messy.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
input ID ADATE MMDDYY10. SERVICE $;&lt;BR /&gt;
format adate date7.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009  I&lt;BR /&gt;
2 1/12/2009  I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/4/2009  OP&lt;BR /&gt;
3 6/5/2009  OP&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data want(keep=id adate service);&lt;BR /&gt;
	if _n_=1 then do;&lt;BR /&gt;
		declare hash h(dataset:'have(keep=id adate rename=(adate=date))', multidata: 'y');&lt;BR /&gt;
		h.defineKey('id');&lt;BR /&gt;
		h.defineData('id', 'date');&lt;BR /&gt;
		h.definedone();&lt;BR /&gt;
	end;&lt;BR /&gt;
	set have;&lt;BR /&gt;
	foundself = 0;&lt;BR /&gt;
	if service ne 'I' then do;&lt;BR /&gt;
		h.find();&lt;BR /&gt;
		if adate = date and foundself = 0 then foundself = 1;&lt;BR /&gt;
		else if (adate = date and foundself = 1) or date = adate-1 then service = 'I';  &lt;BR /&gt;
		h.has_next(result: r);&lt;BR /&gt;
		do while(service ne 'I' and r ne 0);&lt;BR /&gt;
			h.find_next();&lt;BR /&gt;
			if adate = date and foundself = 0 then foundself = 1;&lt;BR /&gt;
			else if (adate = date and foundself = 1) or date = adate-1 then service = 'I';  &lt;BR /&gt;
			h.has_next(result: r);&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]

Message was edited by: polingjw</description>
      <pubDate>Wed, 08 Dec 2010 15:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46433#M12375</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2010-12-08T15:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46434#M12376</link>
      <description>Hi.&lt;BR /&gt;
For the sake of your complex logic , I am afraid you need more iterations.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i;&lt;BR /&gt;
input ID $ ADATE : MMDDYY10. SERVICE $;&lt;BR /&gt;
format adate mmddyy10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009 I&lt;BR /&gt;
2 1/12/2009 I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/5/2009 I&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP &lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=i nodupkey;&lt;BR /&gt;
 by id adate service;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data index;&lt;BR /&gt;
 set i;&lt;BR /&gt;
 where service not eq 'I';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql feedback; *createing table contained observations which is needed to change into I;&lt;BR /&gt;
create table flag as&lt;BR /&gt;
 select  a.*&lt;BR /&gt;
  from index as a left join i as b on a.id eq b.id&lt;BR /&gt;
   where ( b.adate eq a.adate ) or ( b.adate eq (a.adate - 1)) &lt;BR /&gt;
    group by a.id,a.service&lt;BR /&gt;
	 having count(*) ge 2;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=flag nodupkey;&lt;BR /&gt;
 by id adate service;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data flag;&lt;BR /&gt;
 set flag;&lt;BR /&gt;
 service='I';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=i;&lt;BR /&gt;
 by id adate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data result;&lt;BR /&gt;
 merge i flag;&lt;BR /&gt;
 by id adate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Thu, 09 Dec 2010 05:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46434#M12376</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-09T05:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46435#M12377</link>
      <description>Thanks guys, it was very helpful.&lt;BR /&gt;
&lt;BR /&gt;
Sandhya.</description>
      <pubDate>Fri, 10 Dec 2010 15:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46435#M12377</guid>
      <dc:creator>Sandhya</dc:creator>
      <dc:date>2010-12-10T15:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46436#M12378</link>
      <description>Hello Sandhya,&lt;BR /&gt;
&lt;BR /&gt;
    From reading, and rereading, the messages in this thread, I think that I understand your problem well enough now for me to contribute the following code that may be of some use. Of course, there may have been some subtlety that I missed.&lt;BR /&gt;
&lt;BR /&gt;
    During testing, I used the original dataset  that you provided and also the modified one that SPR provided. In both cases, the mainly PROC SQL code below generated the results that I expected. However, of course, that is no guarantee that there are no bugs lurking somewhere in it.&lt;BR /&gt;
&lt;BR /&gt;
    The code below is just something additional that you may want to look at, or consider. It complements the nice responses that others in this thread have contributed.&lt;BR /&gt;
&lt;BR /&gt;
==========================================================&lt;BR /&gt;
options ls=max;&lt;BR /&gt;
&lt;BR /&gt;
data work.ds;&lt;BR /&gt;
input id $ adate:mmddyy10. service $;&lt;BR /&gt;
format adate mmddyy10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009 I&lt;BR /&gt;
2 1/12/2009 I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/4/2009  OP&lt;BR /&gt;
3 6/5/2009  OP&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*--&lt;BR /&gt;
data work.ds;&lt;BR /&gt;
input id $ adate:mmddyy10. service $;&lt;BR /&gt;
format adate mmddyy10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009 I&lt;BR /&gt;
2 1/12/2009 I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/5/2009  I&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP&lt;BR /&gt;
;&lt;BR /&gt;
--*/&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
&lt;BR /&gt;
   create table work.sI as&lt;BR /&gt;
    select *&lt;BR /&gt;
      from work.ds&lt;BR /&gt;
      where service = 'I';&lt;BR /&gt;
&lt;BR /&gt;
   create table work.sNI as&lt;BR /&gt;
    select *&lt;BR /&gt;
      from work.ds&lt;BR /&gt;
      where service not = 'I';&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
  /*---------------------------------------------------------*/&lt;BR /&gt;
  /*-- Identify those records in work.sNI that have the    --*/&lt;BR /&gt;
  /*-- same id as one or more records in work.sI and whose --*/&lt;BR /&gt;
  /*-- adates are either the same as one of these records  --*/&lt;BR /&gt;
  /*-- or corresponds to a record in work.sI that has a    --*/&lt;BR /&gt;
  /*-- date one day earlier than the corresponding work.sNI--*/&lt;BR /&gt;
  /*-- record. The records in the result set for this      --*/&lt;BR /&gt;
  /*-- query are those that need to have their service     --*/&lt;BR /&gt;
  /*-- changed from 'OP' to 'I'.                           --*/&lt;BR /&gt;
  /*---------------------------------------------------------*/ &lt;BR /&gt;
   create table work.needToChange as&lt;BR /&gt;
    select *&lt;BR /&gt;
      from work.sNI&lt;BR /&gt;
     where id in (select id&lt;BR /&gt;
                    from work.sI&lt;BR /&gt;
                   where ((sNI.adate - sI.adate) in (0,1)))&lt;BR /&gt;
           and service = 'OP'; &lt;BR /&gt;
&lt;BR /&gt;
   /*-------------------------------------------------------*/&lt;BR /&gt;
   /*-- Identify the work.sNI records that do NOT need to --*/&lt;BR /&gt;
   /*-- have their service values change from 'OP' to 'I'.--*/&lt;BR /&gt;
   /*-------------------------------------------------------*/&lt;BR /&gt;
   create table work.dontNeedToChange as&lt;BR /&gt;
    select * from work.sNI&lt;BR /&gt;
    except all&lt;BR /&gt;
    select * from work.needToChange;&lt;BR /&gt;
&lt;BR /&gt;
   &lt;BR /&gt;
   /*------------------------------------------------------*/&lt;BR /&gt;
   /*-- Create the new dataset, sorted if need be.       --*/&lt;BR /&gt;
   /*------------------------------------------------------*/&lt;BR /&gt;
   create table work.result as&lt;BR /&gt;
    select id, adate, service from work.sI&lt;BR /&gt;
    union all&lt;BR /&gt;
    select id, adate, 'I' from work.needToChange&lt;BR /&gt;
    union all&lt;BR /&gt;
    select id, adate, service from work.dontNeedToChange&lt;BR /&gt;
    order by id, adate, service;   /* if ordering is desired */&lt;BR /&gt;
    &lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc print; run;&lt;BR /&gt;
==========================================================&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
qseries@sas</description>
      <pubDate>Fri, 10 Dec 2010 23:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46436#M12378</guid>
      <dc:creator>LewisC_sas</dc:creator>
      <dc:date>2010-12-10T23:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46437#M12379</link>
      <description>If you want to use SQL, here is a really quick solution to this problem.  I don't know if it would be efficient for a large data set due to the correlated sub-queries that are used.  &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data work.ds;&lt;BR /&gt;
input id $ adate:mmddyy10. service $;&lt;BR /&gt;
format adate mmddyy10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009 I&lt;BR /&gt;
2 1/12/2009 I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/4/2009 OP&lt;BR /&gt;
3 6/5/2009 OP&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table want as&lt;BR /&gt;
	select id, adate, case&lt;BR /&gt;
		when service = 'I' then 'I'&lt;BR /&gt;
		when (select count(*) from ds as ds1 where ds1.id=ds3.id and ds1.adate = ds3.adate) ge 2 then 'I'&lt;BR /&gt;
		when (select count(*) from ds as ds2 where ds2.id=ds3.id and ds2.adate = ds3.adate - 1) ge 1 then 'I'&lt;BR /&gt;
		else service&lt;BR /&gt;
		end as service&lt;BR /&gt;
	from ds as ds3;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 14 Dec 2010 13:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46437#M12379</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2010-12-14T13:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: checking the range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46438#M12380</link>
      <description>Sorry.I found some problem in my code;&lt;BR /&gt;
The following is corrected code.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i;&lt;BR /&gt;
input ID $ ADATE : MMDDYY10. SERVICE $;&lt;BR /&gt;
format adate mmddyy10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 12/7/2009 I&lt;BR /&gt;
2 1/12/2009 I&lt;BR /&gt;
2 1/13/2009 OP&lt;BR /&gt;
3 6/5/2009 I&lt;BR /&gt;
4 7/29/2009 LA&lt;BR /&gt;
5 3/23/2009 OP &lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=i nodupkey;&lt;BR /&gt;
 by id adate service;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data index;&lt;BR /&gt;
 set i;&lt;BR /&gt;
 where service not eq 'I';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql feedback; *createing table contained observations which is needed to change into I;&lt;BR /&gt;
create table flag as&lt;BR /&gt;
 select  a.*&lt;BR /&gt;
  from index as a left join i as b on a.id eq b.id&lt;BR /&gt;
   where ( b.adate eq a.adate ) or ( b.adate eq (a.adate - 1)) &lt;BR /&gt;
    group by a.id,a.service&lt;BR /&gt;
	 having count(*) ge 2;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=flag nodupkey;&lt;BR /&gt;
 by id adate service;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data flag;&lt;BR /&gt;
 set flag;&lt;BR /&gt;
&lt;B&gt; _service='I';&lt;BR /&gt;
 drop service;&lt;/B&gt;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=i;&lt;BR /&gt;
 by id adate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data result;&lt;BR /&gt;
 merge i flag;&lt;BR /&gt;
 by id adate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;B&gt;data result;&lt;BR /&gt;
 set result;&lt;BR /&gt;
 if  _service eq 'I' then service=_service;&lt;BR /&gt;
 drop _service;&lt;BR /&gt;
run;&lt;/B&gt;</description>
      <pubDate>Mon, 27 Dec 2010 03:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/checking-the-range/m-p/46438#M12380</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-27T03:12:08Z</dc:date>
    </item>
  </channel>
</rss>

