<?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: Subsetting previous observations if a criteria is met in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475288#M71145</link>
    <description>Hahaha, unfortunately the party ends and the machine keeps reading “0” until we refill the alcohol cartridge. So yes, I guess I would have a lot of duplicates. Is there a way to just subset the first “0” observation and the 30 preceding?&lt;BR /&gt;&lt;BR /&gt;Thank you so much for your help with this. I am still getting the hang of SAS.</description>
    <pubDate>Tue, 03 Jul 2018 18:28:46 GMT</pubDate>
    <dc:creator>taylormblack</dc:creator>
    <dc:date>2018-07-03T18:28:46Z</dc:date>
    <item>
      <title>Subsetting previous observations if a criteria is met</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475274#M71138</link>
      <description>&lt;P&gt;I am dealing with real time data from an indoor air monitor.&amp;nbsp; When the monitor runs out of alcohol, the machine reads 0.&amp;nbsp; I am interested in creating a subset of my data that only includes the "0" observations and the preceding 30 observations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I may be able to do this with some form of an IF/THEN statement before OUTPUT, but I am unsure.&amp;nbsp; Maybe something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA library.air_30;
SET library.air;
IF concentration=0 then OUTPUT *previous 30 observations* library.air_30;
RUN; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can anyone offer some help with this?&amp;nbsp; Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 17:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475274#M71138</guid>
      <dc:creator>taylormblack</dc:creator>
      <dc:date>2018-07-03T17:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting previous observations if a criteria is met</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475283#M71142</link>
      <description>&lt;P&gt;Maybe reverse the order of your data and then it becomes a bit easier to look forward rather than backwards?&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/219123"&gt;@taylormblack&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am dealing with real time data from an indoor air monitor.&amp;nbsp; When the monitor runs out of alcohol, the machine reads 0.&amp;nbsp; I am interested in creating a subset of my data that only includes the "0" observations and the preceding 30 observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I may be able to do this with some form of an IF/THEN statement before OUTPUT, but I am unsure.&amp;nbsp; Maybe something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA library.air_30;
SET library.air;
IF concentration=0 then OUTPUT *previous 30 observations* library.air_30;
RUN; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can anyone offer some help with this?&amp;nbsp; Thanks in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 18:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475283#M71142</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-03T18:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting previous observations if a criteria is met</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475287#M71144</link>
      <description>&lt;P&gt;It should be relatively straightforward, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;by concentration notsorted;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;if concentration=0 &lt;FONT color="#ff0000"&gt;and first.concentration&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;do recnum = max(1, _n_ - 30) to _n_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have point=recnum;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, what happens in real life when the alcohol runs out?&amp;nbsp; (I know, the party's over, and everyone goes home.)&amp;nbsp; Could you have several observations in a row that have concentration=0?&amp;nbsp; Would you be retrieving some observations over and over again?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;******************** EDITED in light of new information.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 18:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475287#M71144</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-03T18:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting previous observations if a criteria is met</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475288#M71145</link>
      <description>Hahaha, unfortunately the party ends and the machine keeps reading “0” until we refill the alcohol cartridge. So yes, I guess I would have a lot of duplicates. Is there a way to just subset the first “0” observation and the 30 preceding?&lt;BR /&gt;&lt;BR /&gt;Thank you so much for your help with this. I am still getting the hang of SAS.</description>
      <pubDate>Tue, 03 Jul 2018 18:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-previous-observations-if-a-criteria-is-met/m-p/475288#M71145</guid>
      <dc:creator>taylormblack</dc:creator>
      <dc:date>2018-07-03T18:28:46Z</dc:date>
    </item>
  </channel>
</rss>

