<?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: flag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927192#M364904</link>
    <description>data vs_flag;&lt;BR /&gt;    set vs;&lt;BR /&gt;    by patient;&lt;BR /&gt;&lt;BR /&gt;    retain count_vs ;&lt;BR /&gt;    retain prev_vsresn .;&lt;BR /&gt;    retain prev_vsorresu ;&lt;BR /&gt;&lt;BR /&gt;    if first.patient then do;&lt;BR /&gt;        count_vs = 1;&lt;BR /&gt;        prev_vsresn = vsresn;&lt;BR /&gt;        prev_vsorresu = vsorresu;&lt;BR /&gt;    end;&lt;BR /&gt;    else do;&lt;BR /&gt;        if vsresn = prev_vsresn and vsorresu = prev_vsorresu then count_vs + 1;&lt;BR /&gt;        else do;&lt;BR /&gt;            count_vs = 1;&lt;BR /&gt;            prev_vsresn = vsresn;&lt;BR /&gt;            prev_vsorresu = vsorresu;&lt;BR /&gt;        end;&lt;BR /&gt;    end;&lt;BR /&gt;&lt;BR /&gt;    if count_vs &amp;gt;= 3 then flag = "duplicate record";&lt;BR /&gt;    else flag = "";&lt;BR /&gt;&lt;BR /&gt;/*    drop count_vs prev_vsresn prev_vsorresu;*/&lt;BR /&gt;run;</description>
    <pubDate>Mon, 06 May 2024 17:08:04 GMT</pubDate>
    <dc:creator>112211</dc:creator>
    <dc:date>2024-05-06T17:08:04Z</dc:date>
    <item>
      <title>flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927188#M364901</link>
      <description>&lt;P&gt;data vs ;&lt;BR /&gt;input patient cpevent$ vstest$ vsren vsorresu$;&lt;BR /&gt;cards ;&lt;BR /&gt;100 base pr 78 min&lt;BR /&gt;100 scrn hr 72 /min &lt;BR /&gt;100 week1 sbp 70 mmhg&lt;BR /&gt;100 week7 dbp 110 mm&lt;BR /&gt;100 week21 weight 75 kg&lt;/P&gt;
&lt;P&gt;100 fwp&amp;nbsp; &amp;nbsp;height 120 kg&lt;BR /&gt;100 base pr 78 min&lt;BR /&gt;100 scrn hr 79 /mn &lt;BR /&gt;100 week1 sbp 70 mmhg&lt;BR /&gt;100 week7 dbp 110 mm&lt;BR /&gt;100 week21 weight 80 pounds&lt;/P&gt;
&lt;P&gt;100 fwp height 75 kg&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;Condition below&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If VSTEST having same VSREN and VSORRESU for 4 consecutive visits then highlight those with flag as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"dulipcate record"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on above condition&amp;nbsp; and data , create a flag&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please anyone help me .....&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 17:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927188#M364901</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2024-05-06T17:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927189#M364902</link>
      <description>&lt;P&gt;Please update your question to show the output you would want from the sample data you posted. Also please show the code you have tried.&amp;nbsp; Both of those will help people help you.&amp;nbsp; You might want to consider updating your sample data as well.&amp;nbsp; If I'm understanding what you want, the sample data will not result in any duplicates being flagged.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 16:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927189#M364902</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-05-06T16:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927192#M364904</link>
      <description>data vs_flag;&lt;BR /&gt;    set vs;&lt;BR /&gt;    by patient;&lt;BR /&gt;&lt;BR /&gt;    retain count_vs ;&lt;BR /&gt;    retain prev_vsresn .;&lt;BR /&gt;    retain prev_vsorresu ;&lt;BR /&gt;&lt;BR /&gt;    if first.patient then do;&lt;BR /&gt;        count_vs = 1;&lt;BR /&gt;        prev_vsresn = vsresn;&lt;BR /&gt;        prev_vsorresu = vsorresu;&lt;BR /&gt;    end;&lt;BR /&gt;    else do;&lt;BR /&gt;        if vsresn = prev_vsresn and vsorresu = prev_vsorresu then count_vs + 1;&lt;BR /&gt;        else do;&lt;BR /&gt;            count_vs = 1;&lt;BR /&gt;            prev_vsresn = vsresn;&lt;BR /&gt;            prev_vsorresu = vsorresu;&lt;BR /&gt;        end;&lt;BR /&gt;    end;&lt;BR /&gt;&lt;BR /&gt;    if count_vs &amp;gt;= 3 then flag = "duplicate record";&lt;BR /&gt;    else flag = "";&lt;BR /&gt;&lt;BR /&gt;/*    drop count_vs prev_vsresn prev_vsorresu;*/&lt;BR /&gt;run;</description>
      <pubDate>Mon, 06 May 2024 17:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927192#M364904</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2024-05-06T17:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927256#M364930</link>
      <description>&lt;P&gt;Below uses amended sample data so it contains at least one case with 4 repeated values. I've also added a variable visit_date. I do hope that your real data contains sufficient data to ensure your analysis runs against data in the required sort order.&lt;/P&gt;
&lt;P&gt;It would also help if you show us the desired result as this will clarify which rows you would want flagged (all of them or only from the 4th repetition onwards).&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile datalines dsd dlm=' ' truncover;
  input patient cpevent$ vstest$ vsren vsorresu$;
  visit_date='01jan2024'd+_n_;
  format visit_date date9.;
cards ;
100 base pr 78 min
100 base pr 78 min
100 scrn hr 72 /min
100 week1 sbp 70 mmhg
100 week7 dbp 110 mm
100 week21 weight 75 kg
100 fwp height 120 kg
100 base pr 78 min
100 base4 pr 78 min
100 base1 pr 78 min
100 base6 pr 78 min
100 base pr 78 min
100 scrn hr 79 /mn
100 week1 sbp 70 mmhg
100 week7 dbp 110 mm
100 week21 weight 80 pounds
100 fwp height 75 kg
;

data want;
  set have;
  by patient visit_date;
  if not first.patient and lag(vsren)=vsren and lag(vsorresu)=vsorresu then occurrence_cnt+1;
  else occurrence_cnt=1;
  multi_flg= (occurrence_cnt&amp;gt;=4);
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2024 01:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927256#M364930</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-07T01:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927298#M364941</link>
      <description>&lt;P&gt;The only way this makes any sense if you process it BY the PATIENT and the VSTEST (vital sign test name).&amp;nbsp; Otherwise you might be comparing Systolic BP readings to Diastolic BP readings and flagging false repetitions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you will need to sort your data, which means you need a sortable variable.&amp;nbsp; Normally that would be some type of visit date or reading date for each observation.&amp;nbsp; For the purpose of an example let's just assume your example data is already in order and just number the observations to create an ordering variable, let's call it ROW.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vs ;
  row+1;
  input patient cpevent$ vstest$ vsren vsorresu$;
cards ;
100 base pr 78 min
100 scrn hr 72 /min
100 week1 sbp 70 mmhg
100 week7 dbp 110 mm
100 week21 weight 75 kg
100 fwp   height 120 kg
100 base pr 78 min
100 scrn hr 79 /mn
100 week1 sbp 70 mmhg
100 week7 dbp 110 mm
100 week21 weight 80 pounds
100 fwp height 75 kg
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can sort the data into an order than can be used to find the repetitious values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=vs ;
  by patient vstest row ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then we can use a double DOW loop to count how many repetitions, set your duplicate FLAG, and then re-read the data so we can output the FLAG on every observation in the group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do reps=1 by 1 until(last.vsorresu);
    set vs;
    by patient vstest vsren vsorresu notsorted;
  end;
  dup_flag = (reps&amp;gt;= 4);
  do _n_=1 to reps;
    set vs;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;None of the observations in your data meet the 4 repeated values criteria.&amp;nbsp; The most reps is only 2.&amp;nbsp; So if we change the criteria to look for 2 or more reps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  dup_flag = (reps&amp;gt;= 2);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We get this result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1715086780063.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96216i739CAF58AEE7BD11/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1715086780063.png" alt="Tom_0-1715086780063.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 12:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag/m-p/927298#M364941</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-07T12:59:49Z</dc:date>
    </item>
  </channel>
</rss>

