<?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 test the occurrence of a certain value before the occurrence of an other value for group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803680#M316456</link>
    <description>&lt;P&gt;Hi there, thanks very much for your reply! I actually only want one check value per ID, like an overall check score... which means if it's 1 then change to 0, it should be 0 for this ID since it is not qualified. Is there a way to do it? Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 23 Mar 2022 20:17:54 GMT</pubDate>
    <dc:creator>SAS_taozi</dc:creator>
    <dc:date>2022-03-23T20:17:54Z</dc:date>
    <item>
      <title>How to test the occurrence of a certain value before the occurrence of an other value for group data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803638#M316448</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a long table (group data) of activation status for equipments&amp;nbsp; we have. Different status 1 = activated 0= not activated. We have measurements across all time points. I wanted to know whether if the occurrence of 0 is before 1 for all equipments (if 1 occurred before 0, meaning that it was activated but later on it's not activated any more,&amp;nbsp;that does not make sense, right? for such data, I need to manually review them). Below is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Status&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is ....&lt;/P&gt;&lt;P&gt;ID Status Check&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;different equipments may have different numbers of records... Do anyone know how to do this? very much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803638#M316448</guid>
      <dc:creator>SAS_taozi</dc:creator>
      <dc:date>2022-03-23T19:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to test the occurrence of a certain value before the occurrence of an other value for group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803644#M316449</link>
      <description>&lt;P&gt;Maybe&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data want;
   set have;
   by id;
   retain check;
   if first.id then check=(status=0);
run;&lt;/PRE&gt;
&lt;P&gt;If you data is not sorted by ID but only grouped add NOTSORTED to the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you do By group processing SAS creates automatic variables that indicate whether the particular record is the first. or last. of the group.&lt;/P&gt;
&lt;P&gt;Retain keeps the value of a variable across data step boundaries.&lt;/P&gt;
&lt;P&gt;The comparison (status=0) will return 1 for true and 0 for false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You did not describe what to do with missing values so I am assuming that status is never missing.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803644#M316449</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-23T19:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to test the occurrence of a certain value before the occurrence of an other value for group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803645#M316450</link>
      <description>&lt;P&gt;It is pretty easy to detect when a zero follows a one.&amp;nbsp; Going back in time and changing flag on the record that had the one would be harder.&amp;nbsp; But you can see them it it is the LAST.STATUS and not LAST.ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id status notsorted ;
  if first.id then check=1;
  if last.status and status=1 and not last.id then check=0;
  retain check;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If we add an extra STATUS=1 for ID=4 you can see how it works a little clearer.&amp;nbsp; Notice that CHECK changes to zero on the second observations for ID=4.&lt;/P&gt;
&lt;PRE&gt;Obs    ID    Status    check

  1     1       0        1
  2     1       0        1
  3     1       0        1
  4     1       1        1
  5     1       1        1
  6     2       0        1
  7     2       1        1
  8     4       1        1
  9     4       1        0
 10     4       0        0
 11     4       0        0

&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803645#M316450</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-23T19:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to test the occurrence of a certain value before the occurrence of an other value for group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803680#M316456</link>
      <description>&lt;P&gt;Hi there, thanks very much for your reply! I actually only want one check value per ID, like an overall check score... which means if it's 1 then change to 0, it should be 0 for this ID since it is not qualified. Is there a way to do it? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 20:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803680#M316456</guid>
      <dc:creator>SAS_taozi</dc:creator>
      <dc:date>2022-03-23T20:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to test the occurrence of a certain value before the occurrence of an other value for group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803682#M316457</link>
      <description>&lt;P&gt;Hi there, thanks very much and for the detailed explanation. I guess first. and last. would not suffice what I want here... Another example I had is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs ID Status&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;So the status actually changes intermittently, I definitely need to manually review it, because for obs 2 and obs 3, status = 1 already occurred but followed by a status = 0. It does not make sense, because for our equipment, once activated, it is not even feasible to deactivate it.... Do you have any ideas to solve this problem? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 20:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803682#M316457</guid>
      <dc:creator>SAS_taozi</dc:creator>
      <dc:date>2022-03-23T20:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to test the occurrence of a certain value before the occurrence of an other value for group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803688#M316460</link>
      <description>&lt;P&gt;So just keep the last observation per ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.id;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to do it in one step then use a double DOW loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.id);
  set have;
  by id status notsorted ;
  if first.id then check=1;
  if last.status and status=1 and not last.id then check=0;
end;
do until (last.id);
  set have;
  by id ;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2022 20:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803688#M316460</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-23T20:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to test the occurrence of a certain value before the occurrence of an other value for group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803697#M316462</link>
      <description>&lt;P&gt;So what is the desired result from this not-actually-supposed-to-happen data? Quite possible but need to understand the actual output needed.&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/419954"&gt;@SAS_taozi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there, thanks very much and for the detailed explanation. I guess first. and last. would not suffice what I want here... Another example I had is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obs ID Status&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;So the status actually changes intermittently, I definitely need to manually review it, because for obs 2 and obs 3, status = 1 already occurred but followed by a status = 0. It does not make sense, because for our equipment, once activated, it is not even feasible to deactivate it.... Do you have any ideas to solve this problem? Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you are getting data like that how is it collected if the status supposedly cannot go from 1 to 0???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 21:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803697#M316462</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-23T21:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to test the occurrence of a certain value before the occurrence of an other value for group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803700#M316463</link>
      <description>&lt;P&gt;Hi there, you are correct, the data should not go from 1 to 0, is should only go from 0 to 1... I guess it's a manual error when recording. I just want to check the overall data quality... when there is data go from 1 to 0, I need to what are the IDs for them, so I could manually check on them again. But I need a list of IDs at least...I don't want to check on every equipment.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 21:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-the-occurrence-of-a-certain-value-before-the/m-p/803700#M316463</guid>
      <dc:creator>SAS_taozi</dc:creator>
      <dc:date>2022-03-23T21:18:28Z</dc:date>
    </item>
  </channel>
</rss>

