<?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: How to flag OBS based on a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330230#M74019</link>
    <description>&lt;P&gt;Sorry I was asleep yesterday. Thank you for your revision.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Feb 2017 16:10:02 GMT</pubDate>
    <dc:creator>YiqunDai</dc:creator>
    <dc:date>2017-02-06T16:10:02Z</dc:date>
    <item>
      <title>How to flag OBS based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330071#M73965</link>
      <description>&lt;P&gt;Dear,'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my data I need to flag all OBS &amp;nbsp;that are after max value for a set of OBS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 4th and 5th OBS are after max value (20) for the sort order of obs.(id,visit). Please help. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; date &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; visit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;value &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T21:29 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T22:29 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T22:49 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T23:29 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2014-03-18T23:39 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output need&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; date &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; visit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;value &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;flag &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T21:29 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T22:29 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T22:49 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-03-18T23:29 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2014-03-18T23:39 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 00:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330071#M73965</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-02-06T00:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag OBS based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330098#M73981</link>
      <description>&lt;P&gt;You can use proc sql to find the maxmum of value, and then use retain statement in data step to label "y" for observations after the maximum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data knveraraju91;
input id 1-2 date E8601DT. visit 23-24 value 25-26;
cards;
1 2014-03-18T21:29:00 1  0
1 2014-03-18T22:29:00 1 10
1 2014-03-18T22:49:00 1 20
1 2014-03-18T23:29:00 1  9
1 2014-03-18T23:39:00 1  2
;
run;&lt;BR /&gt;&lt;BR /&gt;* use sql to find the maximum of value, and let it be a macro value;
proc sql;
select max(value) into :max_value
from knveraraju91;
quit;

data data_flag;
set knveraraju91;
retain flag null;
if value = &amp;amp;max_value then flag = 'y';
else flag = flag;
run;&lt;BR /&gt;
proc print data = data_flag;
format date E8601DT.;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 05:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330098#M73981</guid>
      <dc:creator>YiqunDai</dc:creator>
      <dc:date>2017-02-06T05:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag OBS based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330103#M73983</link>
      <description>&lt;P&gt;Thank you very much for the support.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code also flagging the OBS with maximum value, which is 3rd OBS in my data. I need to flag the OBS after maximum value(4th and 5th in my data). Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 06:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330103#M73983</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-02-06T06:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag OBS based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330122#M73992</link>
      <description>&lt;P&gt;A small change to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75234"&gt;@YiqunDai&lt;/a&gt;&amp;nbsp;code will do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_flag;
set knveraraju91;
retain flag null;
output;     /* line added */
if value = &amp;amp;max_value then flag = 'y';
/* else flag = flag; &amp;lt;&amp;lt;&amp;lt; this line not needed */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you have more than one ID ? If yes then you need addapt it to work per ID:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
input id 1-2 date E8601DT. visit 23-24 value 25-26;
cards;
1 2014-03-18T21:29:00 1  0
1 2014-03-18T22:29:00 1 10
1 2014-03-18T22:49:00 1 20
1 2014-03-18T23:29:00 1  9
1 2014-03-18T23:39:00 1  2
;
run;

proc sql;
create table data_max as
select id, max(value) as max_value
from data1
group by id;
quit;

data data_flag;
merge data1 data_max;
by id;
retain flag;
if first.id then flag=' ';
output;     
if value = max_value then flag = 'y';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 09:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330122#M73992</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-06T09:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag OBS based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330212#M74011</link>
      <description>&lt;P&gt;Thank you very much. It worked. But I am getting this message "variable null uninitialized". So I removed the null and it works fine. Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 15:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330212#M74011</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-02-06T15:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag OBS based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330230#M74019</link>
      <description>&lt;P&gt;Sorry I was asleep yesterday. Thank you for your revision.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 16:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-OBS-based-on-a-condition/m-p/330230#M74019</guid>
      <dc:creator>YiqunDai</dc:creator>
      <dc:date>2017-02-06T16:10:02Z</dc:date>
    </item>
  </channel>
</rss>

