<?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: LAG function help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788280#M252003</link>
    <description>&lt;P&gt;try this (I assume data are sorted):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date date9.;
format date date9.;
cards;
1 1jul2021
1 1jul2021
1 4jul2021
1 10jul2021
1 16jul2021
1 18jul2021
2 1jul2021
2 1jul2021
2 4jul2021
2 10jul2021
2 16jul2021
2 18jul2021
;
run;


data want;

do until(last.id);
  set have;
  by id;

  if first.id or (date - _N_ &amp;gt; 5) then
    do;
      output;
      _N_ = date;
    end;
end;

run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jan 2022 14:34:24 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2022-01-04T14:34:24Z</dc:date>
    <item>
      <title>LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788273#M251999</link>
      <description>I have a long data. I would like to keep all rows if the lag date is more than 5 days, else keep only the first row, for example:&lt;BR /&gt;&lt;BR /&gt;Have:&lt;BR /&gt;id date &lt;BR /&gt;1 1jul2021&lt;BR /&gt;1 1jul2021&lt;BR /&gt;1 4jul2021&lt;BR /&gt;1 10jul2021&lt;BR /&gt;1 16jul2021&lt;BR /&gt;1 18jul2021&lt;BR /&gt;&lt;BR /&gt;Wanted:&lt;BR /&gt;id date&lt;BR /&gt;1 1jul2021&lt;BR /&gt;1 10jul2021&lt;BR /&gt;1 16jul2021&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you!</description>
      <pubDate>Tue, 04 Jan 2022 13:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788273#M251999</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T13:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788277#M252002</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date :date9.;
format date date9.;
cards;
1 1jul2021
1 1jul2021
1 4jul2021
1 10jul2021
1 16jul2021
1 18jul2021
;
data want;
    set have;
    prev_date=lag(date);
    if _n_=1 or date-prev_date&amp;gt;5 then output;
    drop prev_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if there are additional ID values, then what? Please present a data set with multiple IDs and the correct output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you present data sets, please follow my example above and provide working SAS data step code, rather than just text as you did — Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 14:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788277#M252002</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-04T14:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788280#M252003</link>
      <description>&lt;P&gt;try this (I assume data are sorted):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date date9.;
format date date9.;
cards;
1 1jul2021
1 1jul2021
1 4jul2021
1 10jul2021
1 16jul2021
1 18jul2021
2 1jul2021
2 1jul2021
2 4jul2021
2 10jul2021
2 16jul2021
2 18jul2021
;
run;


data want;

do until(last.id);
  set have;
  by id;

  if first.id or (date - _N_ &amp;gt; 5) then
    do;
      output;
      _N_ = date;
    end;
end;

run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 14:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788280#M252003</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-04T14:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788284#M252005</link>
      <description>&lt;P&gt;I have another twist--I have a "flag" variable. If not missing then get the row that associated with smallest date's row (see 1 4jul2021 1), but take if not missing and the flag variable is earliest date not with smallest flag value (see&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1 16jul2021 2 although the 18jul2021 has smaller flag=1&amp;nbsp;)&amp;nbsp;&lt;/SPAN&gt;. How can I do below?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 18jul2021 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wanted:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 19:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788284#M252005</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T19:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788286#M252007</link>
      <description>&lt;P&gt;As I requested, please post your example data as SAS data step code (as in my earlier example) and not text that is not part of a data step.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 14:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788286#M252007</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-04T14:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788291#M252009</link>
      <description>&lt;P&gt;Check _all_ offered solutions. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 15:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788291#M252009</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-04T15:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788309#M252020</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

by id;

*calculates the difference between previous date and current date;
date_diff = dif(date);

*If it's the first record with that ID then sets the difference to missing;
if first.id then date_diff = .;

*If the date difference is less than 5 (if less than or equal to change the sign) and not the first record and deletes it if required;
if date_diff &amp;lt; 5 and not first.id then delete;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Have:&lt;BR /&gt;id date &lt;BR /&gt;1 1jul2021&lt;BR /&gt;1 1jul2021&lt;BR /&gt;1 4jul2021&lt;BR /&gt;1 10jul2021&lt;BR /&gt;1 16jul2021&lt;BR /&gt;1 18jul2021&lt;BR /&gt;2 3jul2021&lt;BR /&gt;2 15jul2021&lt;BR /&gt;&lt;BR /&gt;Wanted:&lt;BR /&gt;id date&lt;BR /&gt;1 1jul2021&lt;BR /&gt;1 10jul2021&lt;BR /&gt;1 16jul2021&lt;BR /&gt;2 3jul2021&lt;BR /&gt;2 15jul2021&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 16:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788309#M252020</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-04T16:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788331#M252023</link>
      <description>&lt;P&gt;I have another twist--I have a "flag" variable. If not missing then get the row that associated with smallest date's row (see 1 4jul2021 1), but take if not missing and the flag variable is earliest date not with smallest flag value (see &lt;SPAN&gt;1 16jul2021 2 although the 18jul2021 has smaller flag=1&amp;nbsp;)&amp;nbsp;&lt;/SPAN&gt;. How can I do below?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 18jul2021 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wanted:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 18:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788331#M252023</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T18:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788332#M252024</link>
      <description>&lt;P&gt;I have another twist--I have a "flag" variable. If not missing then get the row that associated with smallest date's row (see 1 4jul2021 1), but take if not missing and the flag variable is earliest date not with smallest flag value (see&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1 16jul2021 2 although the 18jul2021 has smaller flag=1&amp;nbsp;)&amp;nbsp;&lt;/SPAN&gt;. How can I do below?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 18jul2021 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wanted:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 19:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788332#M252024</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T19:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788333#M252025</link>
      <description>&lt;P&gt;Again, I request data provided as SAS data step code, as I showed in my code, instead of simply text that is not a SAS data step.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 19:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788333#M252025</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-04T19:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788335#M252027</link>
      <description>&lt;LI-CODE lang="sas"&gt;data have;
input id date date9. flag;
format date date9.;
cards;
1 1jul2021 .
1 1jul2021 .
1 4jul2021 1
1 10jul2021 4
1 16jul2021 2
1 18jul2021 1
2 1jul2021 1
2 6jul2021 .
;
run;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 04 Jan 2022 19:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788335#M252027</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T19:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788336#M252028</link>
      <description>&lt;P&gt;Adding "earliest" has now made it VERY important to actually duplicate your data. If your "date" is a character variable then "earliest" is not going to be what you think it is as comparisons with character values will not be in date order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The way you describe use of the "flag" variable doesn't seem to make sense with the shown result. Such as why is the data with no flag value set included in the output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have another twist--I have a "flag" variable. If not missing then get the row that associated with smallest date's row (see 1 4jul2021 1), but take if not missing and the flag variable is earliest date not with smallest flag value (see &lt;SPAN&gt;1 16jul2021 2 although the 18jul2021 has smaller flag=1&amp;nbsp;)&amp;nbsp;&lt;/SPAN&gt;. How can I do below?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1jul2021 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 18jul2021 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wanted:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;id date flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 4jul2021 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 10jul2021 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 16jul2021 2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;/P&gt;
&lt;P&gt;2 6jul2021 .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 19:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788336#M252028</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-04T19:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788338#M252030</link>
      <description>&lt;P&gt;Is it this what you need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date date9. flag;
format date date9.;
cards;
1 1jul2021 .
1 1jul2021 .
1 4jul2021 1
1 10jul2021 4
1 16jul2021 2
1 18jul2021 1
2 1jul2021 1
2 6jul2021 .
;
run;

data want;

_N_ = 0;
do until(last.id);
  set have;
  by id;

  _IORC_ + flag;

  if _IORC_ and (first.id or (date - _N_ &amp;gt;= 5)) then
    do;
      output;
      _N_ = date;
    end;
end;
_IORC_ = 0;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 20:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788338#M252030</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-04T20:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788347#M252032</link>
      <description>&lt;P&gt;Thank you, but it is wrong because the 5 is date difference (LAG) should be used not _n_.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 21:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788347#M252032</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T21:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788348#M252033</link>
      <description>&lt;P&gt;Not necessary earliest because the "flag" variable is important as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 21:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788348#M252033</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T21:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788353#M252035</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Not necessary earliest because the "flag" variable is important as well.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have to interpret your statement " If not missing then get the row that associated with smallest date's row " as referring to the Flag variable. You do not provide any example/description or use for what to do with a missing flag variable value.&lt;/P&gt;
&lt;P&gt;Since none of the Subjid=1 with missing Flag values were included why is the Subjid=2 with a missing flag value included in the output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really have not very clearly described the exact roll the value of the Flag variable plays. Providing example output without clear rules is an incomplete description. I can provide programming that would create the exact example that you show for the given input but it very likely would not work in a general sense because the the actual process or rules have not been provided that indicate why the record with&lt;/P&gt;
&lt;PRE&gt;2 6jul2021 .&lt;/PRE&gt;
&lt;P&gt;is wanted in the output but the records like&lt;/P&gt;
&lt;PRE&gt;1 1jul2021 .&lt;/PRE&gt;
&lt;P&gt;are not wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 21:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788353#M252035</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-04T21:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788354#M252036</link>
      <description>&lt;P&gt;Why is it wrong?&lt;/P&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 21:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788354#M252036</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-04T21:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788356#M252037</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Combination of date and flag should be used:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Check 5 days lag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. If lag is within 5 days then take the first row:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But here can be flag missing or not missing,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If all missing, then just take the first date&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If some not missing, then take the not missing first flag&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If all not missing flag, then take the first date&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When as below data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input id date date9. flag;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2021 1&lt;BR /&gt;1 10jul2021 4&lt;BR /&gt;1 16jul2021 2&lt;BR /&gt;1 18jul2021 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wanted should be as below:&lt;/P&gt;
&lt;P&gt;1 4jul2021 1&lt;/P&gt;
&lt;P&gt;1 10jul2021 2&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when as below data:&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input id date date9. flag;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2022 1&lt;BR /&gt;1 10jul2022 4&lt;BR /&gt;1 16jul2022 2&lt;BR /&gt;1 18jul2022 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then it should be as below:&lt;/P&gt;
&lt;P&gt;1 1jul2021 .&lt;/P&gt;
&lt;P&gt;1 4jul2022 1&lt;/P&gt;
&lt;P&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 00:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788356#M252037</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-05T00:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788370#M252049</link>
      <description>Can you help with below:&lt;BR /&gt;&lt;BR /&gt;When as below data:&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id date date9. flag;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2021 1&lt;BR /&gt;1 10jul2021 4&lt;BR /&gt;1 16jul2021 2&lt;BR /&gt;1 18jul2021 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;Then the wanted data should be as below:&lt;BR /&gt;&lt;BR /&gt;1 4jul2021 1&lt;BR /&gt;1 10jul2021 2&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; But when the data have as below:&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id date date9. flag;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2022 1&lt;BR /&gt;1 10jul2022 4&lt;BR /&gt;1 16jul2022 2&lt;BR /&gt;1 18jul2022 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; Then it should be as below:&lt;BR /&gt;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2022 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .</description>
      <pubDate>Tue, 04 Jan 2022 23:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788370#M252049</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T23:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788371#M252050</link>
      <description>Can you help with below:&lt;BR /&gt;&lt;BR /&gt;When as below data:&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id date date9. flag;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2021 1&lt;BR /&gt;1 10jul2021 4&lt;BR /&gt;1 16jul2021 2&lt;BR /&gt;1 18jul2021 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then the wanted data should be as below:&lt;BR /&gt;&lt;BR /&gt;1 4jul2021 1&lt;BR /&gt;1 10jul2021 2&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But when the data have as below:&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id date date9. flag;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2022 1&lt;BR /&gt;1 10jul2022 4&lt;BR /&gt;1 16jul2022 2&lt;BR /&gt;1 18jul2022 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then it should be as below:&lt;BR /&gt;&lt;BR /&gt;1 1jul2021 .&lt;BR /&gt;1 4jul2022 1&lt;BR /&gt;2 1jul2021 1&lt;BR /&gt;2 6jul2021 .</description>
      <pubDate>Tue, 04 Jan 2022 23:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-help/m-p/788371#M252050</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2022-01-04T23:33:35Z</dc:date>
    </item>
  </channel>
</rss>

