<?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 Grouping observations with start and end marking in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917904#M361578</link>
    <description>&lt;P&gt;Hello SAS users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table where I want to mark every observation with events 'Opened' and 'Close'.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cornelis_0-1708952522838.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94122i75D637FBA95D00D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cornelis_0-1708952522838.png" alt="Cornelis_0-1708952522838.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Column Valve describes the position of a valve, where 1 = open and 0 = close.&lt;/P&gt;
&lt;P&gt;At 26FEB24:04:52 the valve is opened and column 'Status' must mark this with 'Opened'&lt;/P&gt;
&lt;P&gt;At 26FEB24:04:54, the valve is closed and must have the status 'Closed'.&lt;/P&gt;
&lt;P&gt;In fact, the valve is opened during 3 minutes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you give me a clue how to program/add column Status with Opened/Closed taking into account that the valve will be opened for 1, 2, 3 and more minutes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks and looking forward,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cornelis&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Feb 2024 13:09:32 GMT</pubDate>
    <dc:creator>Cornelis</dc:creator>
    <dc:date>2024-02-26T13:09:32Z</dc:date>
    <item>
      <title>Grouping observations with start and end marking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917904#M361578</link>
      <description>&lt;P&gt;Hello SAS users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table where I want to mark every observation with events 'Opened' and 'Close'.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cornelis_0-1708952522838.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94122i75D637FBA95D00D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cornelis_0-1708952522838.png" alt="Cornelis_0-1708952522838.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Column Valve describes the position of a valve, where 1 = open and 0 = close.&lt;/P&gt;
&lt;P&gt;At 26FEB24:04:52 the valve is opened and column 'Status' must mark this with 'Opened'&lt;/P&gt;
&lt;P&gt;At 26FEB24:04:54, the valve is closed and must have the status 'Closed'.&lt;/P&gt;
&lt;P&gt;In fact, the valve is opened during 3 minutes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you give me a clue how to program/add column Status with Opened/Closed taking into account that the valve will be opened for 1, 2, 3 and more minutes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks and looking forward,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cornelis&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 13:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917904#M361578</guid>
      <dc:creator>Cornelis</dc:creator>
      <dc:date>2024-02-26T13:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations with start and end marking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917906#M361579</link>
      <description>&lt;P&gt;It is not clear (to me) in which way the Datetime has an influence on the Status variable.&lt;/P&gt;
&lt;P&gt;Please not that it will be easier to help you would post the data in usable form.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 14:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917906#M361579</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-02-26T14:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations with start and end marking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917914#M361583</link>
      <description>&lt;P&gt;Hello Andreas,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cornelis_0-1708959729762.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94125i749469F1C495C8A0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cornelis_0-1708959729762.png" alt="Cornelis_0-1708959729762.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Column Status is the resulting output after running a SAS program.&lt;/P&gt;
&lt;P&gt;Observation 3: The valve is open and the datetime =&amp;nbsp;26FEB24:04:52:00.&lt;/P&gt;
&lt;P&gt;At&amp;nbsp;&amp;nbsp;26FEB24:04:54:00, observation 5, the valve is still open, but will be closed of very soon, so the Status is marked as 'Close".&lt;/P&gt;
&lt;P&gt;The total time that a valve is open lies between 04:52 - 04:54 hour.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this make sense?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cornelis&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 15:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917914#M361583</guid>
      <dc:creator>Cornelis</dc:creator>
      <dc:date>2024-02-26T15:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations with start and end marking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917918#M361586</link>
      <description>&lt;P&gt;Please provide your sample data in the form of a working DATA step.&amp;nbsp; The program below is untested in the absence of such sample data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by valve notsorted;
  if valve=1 then do;
    if first.valve=1 and last.valve=1 then status='Open and Closed';
    else if first.valve=1 then status='Open';
    else if last.valve=1 then status='Closed';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "notsorted" option of the BY statement is especially useful here, since it allows you to track changes between valve=1 and valve=0, without regard to whether the valve change is positive or negative.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 15:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917918#M361586</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-02-26T15:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations with start and end marking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917998#M361619</link>
      <description>&lt;P&gt;Thank you very much for your quick solution!&lt;/P&gt;
&lt;P&gt;The not-sorted option do the trick.&lt;/P&gt;
&lt;P&gt;Indeed, supplying the SAS code is helpful. For the completeness, here is the SAS code and already validated:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input valve $1-2 datetime $3-20 ;
cards;
0	26FEB24:04:51:00
1	26FEB24:04:52:00
1	26FEB24:04:53:00
1	26FEB24:04:54:00
0	26FEB24:04:55:00
0	26FEB24:04:56:00
0	26FEB24:04:57:00
1	26FEB24:04:58:00
1	26FEB24:04:59:00
0	26FEB24:05:00:00
0	26FEB24:05:01:00
1	26FEB24:05:02:00
0	26FEB24:05:03:00
0	26FEB24:05:04:00
;
run;



data want;
  set have;
  by valve notsorted;
  if valve=1 then do;
    if first.valve=1 and last.valve=1 then status1='Open and Closed';
    else if first.valve=1 then status1='Open';
    else if last.valve=1 then status1='Closed';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Feb 2024 06:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-with-start-and-end-marking/m-p/917998#M361619</guid>
      <dc:creator>Cornelis</dc:creator>
      <dc:date>2024-02-27T06:51:30Z</dc:date>
    </item>
  </channel>
</rss>

