<?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: process repeated measure data of unequal follow-up - potentially need LAG function in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/520735#M16126</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result(drop=lag_RuralPrac52w); &lt;BR /&gt;	set manyevents(keep=StudentID Year RuralPrac52w);&lt;BR /&gt; 	by StudentID Year;&lt;BR /&gt; 	lag_RuralPrac52w=lag(RuralPrac52w);&lt;BR /&gt; 	select;&lt;BR /&gt; 		when(first.StudentID) CorrEventCount=(RuralPrac52w=1);&lt;BR /&gt; 		when(lag_RuralPrac52w=0 and RuralPrac52w=1) CorrEventCount+1;&lt;BR /&gt; 	        otherwise;&lt;BR /&gt; 	end; &lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Dec 2018 10:40:46 GMT</pubDate>
    <dc:creator>learsaas</dc:creator>
    <dc:date>2018-12-12T10:40:46Z</dc:date>
    <item>
      <title>process repeated measure data of unequal follow-up - potentially need LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/520696#M16125</link>
      <description>&lt;P&gt;Hello fellow SAS users&lt;/P&gt;&lt;P&gt;I have been working on the problem below over the past few days with very little success, and would very much appreciate your help here.&lt;/P&gt;&lt;P&gt;Attach is a sample dataset in Excel that illustrates the data structure and what I want to achieve.&lt;/P&gt;&lt;P&gt;Variable 'StudentID' is self-explanatory, indicating unique individuals.&lt;/P&gt;&lt;P&gt;Variable 'Year' shows the yearly follow-up, in chronological order. Here, you can see that the duration of follow-up varies for each individual (between 3 and 7 years). In the real dataset I am working on, this varies from 2 to 10 years.&lt;/P&gt;&lt;P&gt;Variable 'RuralPrac52w' indicates the event of interest in that year (1 for Yes, 0 for No).&lt;/P&gt;&lt;P&gt;The final variable 'CorrEventCount' is what I wish to obtain from my coding (and I have not got there yet - which is why I am here).&lt;/P&gt;&lt;P&gt;The logic/rule to create this final variable is quite simple, in plain English. It is similar to the counting process for repeated events in survival analysis. It goes like this:&lt;/P&gt;&lt;P&gt;Within each unique StudentID, if RuralPrac52w=1 then it is 1 count for an event, whether this is for that particular year/row only, or for however many consecutive years. If there is a break in the event series (ie with a 0 in between), the counting will continue to the next event when another 1 occurs. Ultimately, Person 1 has 1 event of a continuous 2-year duration. Person 2 has 2 events, each of 1 year duration. Person 3 has 1 event of 3-year duration. Person 4 has 3 events (1st lasting 2 years, 2nd &amp;amp; 3rd 1 year each). Person 5 has 1 event of 5-year duration.&lt;/P&gt;&lt;P&gt;My two main challenges are: (i) the changeable/unfixed durations of the event within-ID and of the follow-up period between-ID; and (ii) how to continue/resume the counting once the series is interrupted (ie from 1 to 0, or 0 to 1), and keep this process going until the last record for that person.&lt;/P&gt;&lt;P&gt;Below is one of my recent (unsuccessful) syntax versions.&lt;/P&gt;&lt;P&gt;data manyevents_count;&lt;BR /&gt;&amp;nbsp;set manyevents;&lt;BR /&gt;&amp;nbsp;by StudentID;&lt;BR /&gt;&amp;nbsp;retain countEvent;&lt;BR /&gt;&amp;nbsp;do i = 1 to last.StudentID;&lt;BR /&gt;&amp;nbsp;*set base value: 0 or 1 as approp;&lt;BR /&gt;&amp;nbsp;countEvent=RuralPrac52w;&lt;BR /&gt;&amp;nbsp;if RuralPrac52w=1 AND lag(lag(RuralPrac52w))=1 then countEvent=1;&lt;BR /&gt;&amp;nbsp;if RuralPrac52w=1 AND lag(lag(RuralPrac52w))=0 then countEvent=1;&lt;BR /&gt;&amp;nbsp;if RuralPrac52w=0 AND lag(lag(RuralPrac52w))=0 then countEvent=0;&lt;BR /&gt;&amp;nbsp;if RuralPrac52w=0 AND lag(lag(RuralPrac52w))=1 then countEvent=1;&lt;BR /&gt;&amp;nbsp;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Look forward to any help or advice.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 07:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/520696#M16125</guid>
      <dc:creator>humbleSASer</dc:creator>
      <dc:date>2018-12-12T07:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: process repeated measure data of unequal follow-up - potentially need LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/520735#M16126</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result(drop=lag_RuralPrac52w); &lt;BR /&gt;	set manyevents(keep=StudentID Year RuralPrac52w);&lt;BR /&gt; 	by StudentID Year;&lt;BR /&gt; 	lag_RuralPrac52w=lag(RuralPrac52w);&lt;BR /&gt; 	select;&lt;BR /&gt; 		when(first.StudentID) CorrEventCount=(RuralPrac52w=1);&lt;BR /&gt; 		when(lag_RuralPrac52w=0 and RuralPrac52w=1) CorrEventCount+1;&lt;BR /&gt; 	        otherwise;&lt;BR /&gt; 	end; &lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Dec 2018 10:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/520735#M16126</guid>
      <dc:creator>learsaas</dc:creator>
      <dc:date>2018-12-12T10:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: process repeated measure data of unequal follow-up - potentially need LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/520738#M16127</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250859"&gt;@humbleSASer&lt;/a&gt;&amp;nbsp;and&amp;nbsp;welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data manyevents_count;
set manyevents;
by StudentID RuralPrac52w notsorted;
if first.StudentID then CorrEventCount=0;
CorrEventCount+(first.RuralPrac52w &amp;amp; RuralPrac52w=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the above BY statement the DATA step sees the data as blocks of consecutive observations with the same StudentID which in turn consist of&amp;nbsp;&lt;SPAN&gt;blocks of consecutive observations with the same&amp;nbsp;RuralPrac52w value. (The NOTSORTED option is necessary because the RuralPrac52w values within a StudentID are neither increasing nor decreasing in general.) It is assumed that dataset MANYEVENTS is sorted by StudentID Year.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The IF-THEN statement initializes the count to zero at the first observation of each student. The sum statement (of the general form &lt;FONT face="courier new,courier"&gt;&lt;EM&gt;variable&lt;/EM&gt;+&lt;EM&gt;increment&lt;/EM&gt;;&lt;/FONT&gt;) increments CorrEventCount by 1 if the Boolean expression in the parentheses is true, i.e., if a new block of RuralPrac52w values (within a student) begins and this is a block with RuralPrac52w=1.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 10:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/520738#M16127</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-12T10:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: process repeated measure data of unequal follow-up - potentially need LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/521152#M16140</link>
      <description>&lt;P&gt;Many thanks learsaas! Have tested and it worked!!&lt;/P&gt;&lt;P&gt;Kind regards, H&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 15:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/521152#M16140</guid>
      <dc:creator>humbleSASer</dc:creator>
      <dc:date>2018-12-13T15:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: process repeated measure data of unequal follow-up - potentially need LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/521153#M16141</link>
      <description>&lt;P&gt;Many thanks FreelanceReinhard! Also tested your syntax and it worked!&lt;/P&gt;&lt;P&gt;Kind regards, H&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 15:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/process-repeated-measure-data-of-unequal-follow-up-potentially/m-p/521153#M16141</guid>
      <dc:creator>humbleSASer</dc:creator>
      <dc:date>2018-12-13T15:15:47Z</dc:date>
    </item>
  </channel>
</rss>

