<?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: by group processing and loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320744#M70686</link>
    <description>It works perfectly! Thank you very much!&lt;BR /&gt;&lt;BR /&gt;Xiaoyan</description>
    <pubDate>Thu, 22 Dec 2016 15:01:43 GMT</pubDate>
    <dc:creator>zhuxiaoyan1</dc:creator>
    <dc:date>2016-12-22T15:01:43Z</dc:date>
    <item>
      <title>by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320529#M70621</link>
      <description>&lt;P&gt;The following is part of my data: If you can't see this because of format issue, please see the attached data.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;FAMILY_ID&lt;/TD&gt;&lt;TD&gt;FROMDATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000130758&lt;/TD&gt;&lt;TD&gt;01Jan2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000130758&lt;/TD&gt;&lt;TD&gt;11Feb2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000130758&lt;/TD&gt;&lt;TD&gt;01Mar2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000535847&lt;/TD&gt;&lt;TD&gt;21Dec2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000535847&lt;/TD&gt;&lt;TD&gt;22Dec2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001808772&lt;/TD&gt;&lt;TD&gt;01May2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001808772&lt;/TD&gt;&lt;TD&gt;02May2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001808772&lt;/TD&gt;&lt;TD&gt;03May2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;009084285&lt;/TD&gt;&lt;TD&gt;30Jan2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;009084285&lt;/TD&gt;&lt;TD&gt;01Mar2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;23Aug2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;24Sep2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;23Oct2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;24Nov2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;567835520&lt;/TD&gt;&lt;TD&gt;24Dec2015&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;keep the&amp;nbsp;fromdate If&amp;nbsp;each distinct family_ID has only one fromdate. If each distinct family_ID has multiple fromdate, then compare the later fromdate and earlier fromdate. If the difference between&amp;nbsp;later fromdate and earlier fromdate is &amp;gt; 30 then keep both date, then keep both fromdate; if the difference between&amp;nbsp;later fromdate and earlier fromdate is&amp;nbsp;&amp;lt;= 30, then keep only the earlier fromdate. For example, for family_ID &amp;nbsp;000130758, I keep all of three fromdate; for family_ID 000535847, I only keep the earlier fromdate 21Dec2015 and delete the fromdate 22Dec2015.&lt;/P&gt;&lt;P&gt;I appreciate any solutions and/or suggestions!&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320529#M70621</guid>
      <dc:creator>zhuxiaoyan1</dc:creator>
      <dc:date>2016-12-21T15:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320538#M70624</link>
      <description>&lt;P&gt;Assumind data is sorted by family ID &amp;nbsp;fromdate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;by family_id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if first.family_id then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lagdate = lag(fromdate); &amp;nbsp;/* previous observarion date */&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if fromdate - lagdate &amp;gt; 30 then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320538#M70624</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-21T15:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320542#M70626</link>
      <description>&lt;P&gt;You said you keep all the three for family_id 130758. Here family_id 130758 has 3 records. Is your criteria when it has more than 2 is to check the date diff with only first and last record.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;000130758 01Jan2016&lt;BR /&gt;000130758 11Feb2016&lt;BR /&gt;000130758 01Mar2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when you compare first two records then date diff is &amp;gt;30 so keep both. when you compare 2 and 3rd record then date diff is &amp;lt;30 then should keep only 2nd record. Finally it should have only two records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Correct me if I'm wrong.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 16:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320542#M70626</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2016-12-21T16:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320559#M70630</link>
      <description>Yes, you are right. It should have only 2 records for family_ID 00130758. I said it wrong. I'm very sorry about this.&lt;BR /&gt;&lt;BR /&gt;Xiaoyan Zhu&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Dec 2016 17:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320559#M70630</guid>
      <dc:creator>zhuxiaoyan1</dc:creator>
      <dc:date>2016-12-21T17:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320584#M70632</link>
      <description>&lt;P&gt;Please check this output&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1 ;
record=_n_+1;
set have end=last;
if not last then set have(keep=fromdate rename=(fromdate=fromdate2)) point=record;
else call missing(fromdate2);
run;

data want2 ;
set want1;
by FAMILY_ID;
lagdate=lag(fromdate);
if last.FAMILY_ID then fromdate2=.;
if first.family_id then lagdate=.;
fromdiff=ifn((fromdate2-fromdate)&amp;gt;30,(fromdate2-fromdate),.);
lagdiff=ifn((fromdate-lagdate)&amp;gt;30,(fromdate-lagdate),.);
result=coalesce(lagdiff,fromdiff);
format lagdate date9.;
if result ne .;
drop fromdate2 lagdate fromdiff lagdiff result;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Dec 2016 18:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320584#M70632</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-21T18:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320586#M70633</link>
      <description>&lt;P&gt;You want to look both forward and backward to find records within 30 days of a predecessor or successor.&amp;nbsp;&amp;nbsp; This is an appropriate context to use the LAG functions&amp;nbsp; (to see if current record is near its predecessor) and also a MERGE with FIrSTOBS=2 parameter (to&amp;nbsp; see if current record is near to successor).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the family_id is a character var, then change "dif(family_id)^=0" to "family_id^=lag(family_id)".&amp;nbsp; and an analogous change for "dif(family_id)=0".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; want (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;=nxt:);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;merge&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; have (firstobs=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; keep=family_id fromdate rename=(family_id=nxtfid fromdate=nxtfd));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; (dif(family_id)^=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; and nxtfid^=family_id) &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New"&gt;/* Single record*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; or&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(nxtfid=family_id and (nxtfd-fromdate)&amp;lt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;30&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;) &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New"&gt;/* Early member of 30-day pair*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; or&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(dif(family_id)=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; and dif(fromdate)&amp;lt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;30&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;) &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New"&gt;/* Late member of 30-day pair*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 18:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320586#M70633</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-21T18:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320597#M70634</link>
      <description>You have received a secure message from "Zhu, Xiaoyan" entitled, "Re: by group processing and loop".&lt;BR /&gt;&lt;BR /&gt;You can view the message (before 01/04/2017) at the following web address:&lt;BR /&gt;&lt;A href="https://mg.usablecs.com/enduser/msg.html?x=d-07507df3c11041317d318b077abb618f9cee1286b2d1eef009b5d59132b08b6de7107036650f4af1a027a54dc850a7fa8cbe6eb4afd44ddcbf856300497ab7ff" target="_blank"&gt;https://mg.usablecs.com/enduser/msg.html?x=d-07507df3c11041317d318b077abb618f9cee1286b2d1eef009b5d59132b08b6de7107036650f4af1a027a54dc850a7fa8cbe6eb4afd44ddcbf856300497ab7ff&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-----------------------------------------------------------------------------------------&lt;BR /&gt;Delivered with MailGate SC (TM)&lt;BR /&gt;&lt;A href="http://www.axway.com" target="_blank"&gt;http://www.axway.com&lt;/A&gt;&lt;BR /&gt;MailGate SC is a trademark of Axway.</description>
      <pubDate>Wed, 21 Dec 2016 19:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320597#M70634</guid>
      <dc:creator>zhuxiaoyan1</dc:creator>
      <dc:date>2016-12-21T19:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320606#M70635</link>
      <description>&lt;P&gt;I guess your condition dosen't have a proper reason, beacuase consider this group&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;23Aug2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;24Sep2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;23Oct2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;035064420&lt;/TD&gt;&lt;TD&gt;24Nov2015&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;When you condider row 1 and 2 the difference is &amp;gt;30 so you need both of them. when considering row 2 and 3 difference is &amp;lt;30 then you only need row 2 and not the row 3. Now here comes the problem, when you consider row 3 and row 4 the difference is &amp;gt;30 so youy need both the rows 3 and 4. So according to your condition the row 3 is satsifing and even not satsifing. confusing&lt;img id="smileysurprised" class="emoticon emoticon-smileysurprised" src="https://communities.sas.com/i/smilies/16x16_smiley-surprised.png" alt="Smiley Surprised" title="Smiley Surprised" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 20:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320606#M70635</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2016-12-21T20:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320615#M70637</link>
      <description>&lt;P&gt;So I keep row1, row2 and row4. It is confusing. but this is what my boss wants.&lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://communities.sas.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 20:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320615#M70637</guid>
      <dc:creator>zhuxiaoyan1</dc:creator>
      <dc:date>2016-12-21T20:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320629#M70639</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; one;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; FAMILY_ID :&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;9.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; FROMDATE &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&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; FROMDATE &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;000130758 01Jan2016&lt;/P&gt;&lt;P&gt;000130758 11Feb2016&lt;/P&gt;&lt;P&gt;000130758 01Mar2016&lt;/P&gt;&lt;P&gt;000535847 21Dec2015&lt;/P&gt;&lt;P&gt;000535847 22Dec2015&lt;/P&gt;&lt;P&gt;001808772 01May2016&lt;/P&gt;&lt;P&gt;001808772 02May2016&lt;/P&gt;&lt;P&gt;001808772 03May2016&lt;/P&gt;&lt;P&gt;009084285 30Jan2016&lt;/P&gt;&lt;P&gt;009084285 01Mar2016&lt;/P&gt;&lt;P&gt;035064420 23Aug2015&lt;/P&gt;&lt;P&gt;035064420 24Sep2015&lt;/P&gt;&lt;P&gt;035064420 23Oct2015&lt;/P&gt;&lt;P&gt;035064420 24Nov2015&lt;/P&gt;&lt;P&gt;567835520 24Dec2015&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=one;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; family_id fromdate;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&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; two (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=lag_family_id lag_fromdate lead_fromdate lagdate days);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; one one(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;firstobs&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=fromdate &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;rename&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=(fromdate=lead_fromdate));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;lag_family_id=lag(family_id);&lt;/P&gt;&lt;P&gt;lag_fromdate=lag(fromdate);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; family_id=lag_family_id &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; lagdate=lag_fromdate;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; lagdate=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; lagdate=lead_fromdate;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;days=ABS(INTCK(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'days'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,lagdate,fromdate));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; days&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;30&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;or&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; days=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 21:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320629#M70639</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2016-12-21T21:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320632#M70640</link>
      <description>I also need these two rowes:&lt;BR /&gt;000535847 21Dec2015&lt;BR /&gt;001808772 01May2016&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Dec 2016 21:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320632#M70640</guid>
      <dc:creator>zhuxiaoyan1</dc:creator>
      <dc:date>2016-12-21T21:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320633#M70641</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; one;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; FAMILY_ID :&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;9.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; FROMDATE &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&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; FROMDATE &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;000130758 01Jan2016&lt;/P&gt;&lt;P&gt;000130758 11Feb2016&lt;/P&gt;&lt;P&gt;000130758 01Mar2016&lt;/P&gt;&lt;P&gt;000535847 21Dec2015&lt;/P&gt;&lt;P&gt;000535847 22Dec2015&lt;/P&gt;&lt;P&gt;001808772 01May2016&lt;/P&gt;&lt;P&gt;001808772 02May2016&lt;/P&gt;&lt;P&gt;001808772 03May2016&lt;/P&gt;&lt;P&gt;009084285 30Jan2016&lt;/P&gt;&lt;P&gt;009084285 01Mar2016&lt;/P&gt;&lt;P&gt;035064420 23Aug2015&lt;/P&gt;&lt;P&gt;035064420 24Sep2015&lt;/P&gt;&lt;P&gt;035064420 23Oct2015&lt;/P&gt;&lt;P&gt;035064420 24Nov2015&lt;/P&gt;&lt;P&gt;567835520 24Dec2015&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=one;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; family_id fromdate;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&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; two &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*(drop=lag_family_id lag_fromdate lead_fromdate lagdate days)*/&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; one one(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;firstobs&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=fromdate &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;rename&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=(fromdate=lead_fromdate));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;lag_family_id=lag(family_id);&lt;/P&gt;&lt;P&gt;lag_fromdate=lag(fromdate);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; family_id=lag_family_id &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; lagdate=lag_fromdate;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; lagdate=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; lagdate=lead_fromdate;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;days=ABS(INTCK(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'days'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,lagdate,fromdate));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&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; three(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=days);&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; two (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=lag_family_id lag_fromdate lead_fromdate lagdate);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; family_id;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first.family_id &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;or&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; days&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;30&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 21:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320633#M70641</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2016-12-21T21:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320635#M70642</link>
      <description>Thank you so much!&lt;BR /&gt;&lt;BR /&gt;Xiaoyan</description>
      <pubDate>Wed, 21 Dec 2016 21:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320635#M70642</guid>
      <dc:creator>zhuxiaoyan1</dc:creator>
      <dc:date>2016-12-21T21:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320665#M70650</link>
      <description>&lt;P&gt;I updated my previous code as to get your expectated output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1 ;
record=_n_+1;
set have end=last;
if not last then set have(keep=fromdate rename=(fromdate=fromdate2)) point=record;
else call missing(fromdate2);
run;

data want2 ;
set want1;
by FAMILY_ID;
lagdate=lag(fromdate);
if last.FAMILY_ID then fromdate2=.;
if first.family_id then lagdate=.;
fromdiff=fromdate2-fromdate;
lagdiff=fromdate-lagdate;
result=coalesce(lagdiff,fromdiff);
format lagdate date9.;
if first.family_id or result &amp;gt;30;
drop fromdate2 lagdate fromdiff lagdiff result;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2016 02:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320665#M70650</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-22T02:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: by group processing and loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320744#M70686</link>
      <description>It works perfectly! Thank you very much!&lt;BR /&gt;&lt;BR /&gt;Xiaoyan</description>
      <pubDate>Thu, 22 Dec 2016 15:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-group-processing-and-loop/m-p/320744#M70686</guid>
      <dc:creator>zhuxiaoyan1</dc:creator>
      <dc:date>2016-12-22T15:01:43Z</dc:date>
    </item>
  </channel>
</rss>

