<?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 do I subset rows based on a range of values? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-rows-based-on-a-range-of-values/m-p/626998#M20474</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308380"&gt;@asgee&lt;/a&gt;&amp;nbsp; Assuming I understand your requirement--&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID $	Data;
cards;
AAA	14.00
AAA	13.00
BB	18.00
BB	21.00
CC	19.00
CC	14.00
CC	10.00
DDD	9.00
DDD	12.00
EE	11.00
EE	17.00
EE	10.00
;

data want;
 do _n_=1 by 1 until(last.id);
  set have;
  by id;
  if 0 &amp;lt; data &amp;lt; 15.0 then _count=sum(_count,1);
  else _count=0;
  if _count&amp;gt;=2 then _flag=1;
 end;
 do _n_=1 to _n_;
  set have;
  if _flag then output;
 end;
 drop _:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Feb 2020 19:55:31 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-02-24T19:55:31Z</dc:date>
    <item>
      <title>How do I subset rows based on a range of values?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-rows-based-on-a-range-of-values/m-p/626990#M20471</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on a dataset where some IDs have repeated measurements over time. A template example is shown below. The data is displayed in chronological order (i.e. time 1, time 2, time 3, etc...):&lt;/P&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&gt;EE&lt;/TD&gt;&lt;TD&gt;11.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;EE&lt;/TD&gt;&lt;TD&gt;17.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;EE&lt;/TD&gt;&lt;TD&gt;10.00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each data obtained per ID was collected longitudinally, meaning that the data is in chronological order. This is important since I want to only obtain those ID's where the data was &amp;lt; 15.00&amp;nbsp; between two-points back-to-back.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, "AAA" would count since between time 1 and time 2, the data taken indicates that its &amp;lt; 15.00.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ID "CC" on the other hand has 3 data points (19.00, 14.00, and 10.00). In this case, the cut-off (&amp;lt; 15.00) would apply for this subject since at Time 2 (data = 14.00) and Time 3 (10.00), were obtained right after the other.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the other hand, the ID "EE" also has 3 data points, but the cut-off (&amp;lt;15.00) applies for Time 1 (data = 11.00) and Time 3 (data = 10.00), therefore, this ID would not meet the requirement of (&amp;lt; 15.00) AND that they have to be right after each other.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to subset the subjects so that I end up with something like this:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Data&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AAA&lt;/TD&gt;&lt;TD&gt;14.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AAA&lt;/TD&gt;&lt;TD&gt;13.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CC&lt;/TD&gt;&lt;TD&gt;19.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CC&lt;/TD&gt;&lt;TD&gt;14.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CC&lt;/TD&gt;&lt;TD&gt;10.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DDD&lt;/TD&gt;&lt;TD&gt;9.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DDD&lt;/TD&gt;&lt;TD&gt;12.00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, only those ID's where the cut-off was &amp;lt;15.00 and where two observations were identified as &amp;lt;15.00 right after the other (in the case of "CC") were drawn. Important that in the case for "CC", the first time point where data = 19.00 was still drawn since I'm less concerned about the raw numbers per se, but more so that this ID at any point met the criteria of &amp;lt;15.00 in two subsequent time points.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attempted to run the code below, but it seems that this doesn't achieve the restriction that I wanted to do:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set master;
if ID ne (0 &amp;lt; data &amp;lt; 15.0) then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help would be very much appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AG&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 19:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-rows-based-on-a-range-of-values/m-p/626990#M20471</guid>
      <dc:creator>asgee</dc:creator>
      <dc:date>2020-02-24T19:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subset rows based on a range of values?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-rows-based-on-a-range-of-values/m-p/626998#M20474</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308380"&gt;@asgee&lt;/a&gt;&amp;nbsp; Assuming I understand your requirement--&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID $	Data;
cards;
AAA	14.00
AAA	13.00
BB	18.00
BB	21.00
CC	19.00
CC	14.00
CC	10.00
DDD	9.00
DDD	12.00
EE	11.00
EE	17.00
EE	10.00
;

data want;
 do _n_=1 by 1 until(last.id);
  set have;
  by id;
  if 0 &amp;lt; data &amp;lt; 15.0 then _count=sum(_count,1);
  else _count=0;
  if _count&amp;gt;=2 then _flag=1;
 end;
 do _n_=1 to _n_;
  set have;
  if _flag then output;
 end;
 drop _:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 19:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-rows-based-on-a-range-of-values/m-p/626998#M20474</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-24T19:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subset rows based on a range of values?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-rows-based-on-a-range-of-values/m-p/627006#M20475</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes this is exactly what I'm looking for! Thanks for your help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 20:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-rows-based-on-a-range-of-values/m-p/627006#M20475</guid>
      <dc:creator>asgee</dc:creator>
      <dc:date>2020-02-24T20:20:37Z</dc:date>
    </item>
  </channel>
</rss>

