<?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: Need help on SAS code for calculating survival follow up time (person years) in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261077#M2054</link>
    <description>&lt;P&gt;But for ID2, there are TWO years from hbp3 to hbp5 (5 minus 3), and half of that is ONE year. 3 + 1 = 4.&lt;/P&gt;
&lt;P&gt;Your value of 3.5 for ID 2 contradicts your example in&lt;/P&gt;
&lt;P&gt;"Any missing value between 0..1 stays the same as missing, and the person_years for this period=1/2 length of time from 0..to..1 (ex: hbp2...hbp5: 1/2 length of time is 1.5 years)"&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2016 13:29:52 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-04-04T13:29:52Z</dc:date>
    <item>
      <title>Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261032#M2046</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I'm working with a longitudinal data with structure as below:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;
&lt;P&gt;ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;Hbp1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;Hbp2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;Hbp3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;Hbp4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;Hbp5&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="104"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hbp1-Hbp5: hypertension(0: no, 1:yes) from year 1 to year 5.&lt;/P&gt;
&lt;P&gt;I want to calculate person-years (survival time) and incidence rate for this data but I failed to write the SAS code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's very easy to calculate by hand. Incidence case is defined as the first time the event appears during the follow-up period.&lt;/P&gt;
&lt;P&gt;For example, ID 1 has 4+0.5 =4.5 person-years, Id 2 has 3+0.5=3.5 person-years, ID 3 has 4 person-years (missing values before the last observation are considered 0)...&lt;/P&gt;
&lt;P&gt;But impossible to do that with big sample size.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anybody have experience with calculating survival time using this data structure in SAS? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 09:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261032#M2046</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-04T09:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261033#M2047</link>
      <description>&lt;P&gt;Sorry I have 1 correction:&lt;/P&gt;
&lt;P&gt;Missing values before Observation with value 0 are consider 0&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Missing values before Observation with value 1 are still missing values.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 10:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261033#M2047</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-04T10:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261036#M2048</link>
      <description>&lt;P&gt;Why does ID 3 have 4 years and not 4.5 or 5.5? And why does ID 2 get 3.5 years when only the last value may be considered 1 when missing?&lt;/P&gt;
&lt;P&gt;Nonetheless:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array hbp {*} hbp1-hbp5;
i = 1;
do while (i &amp;lt;= dim(hbp) and hbp{i} ne 1);
  i + 1;
end;
person_years = i - .5;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2016 10:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261036#M2048</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-04T10:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261041#M2049</link>
      <description>&lt;P&gt;Dear Kurt,&lt;/P&gt;
&lt;P&gt;Thank you very much for your quick reply.&lt;/P&gt;
&lt;P&gt;You're right, some of my calcultion are wrong.&lt;/P&gt;
&lt;P&gt;I checked your code and have error as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;55&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;56 data want;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;57 set hbp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;58 array hbp {*} hbp1-hbp5;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;59 i = 1;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;60 do while (i &amp;lt;= dim(hbp) and hbp{i} ne 1);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;61 i + 1;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;62 end;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;63 person_years = i - .5;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;64 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogError1_1459765923323" class="sasError"&gt;ERROR: Array subscript out of range at line 60 column 29.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;id=2 hbp1=0 hbp2=0 hbp3=0 hbp4=. hbp5=. i=6 person_years=. _ERROR_=1 _N_=2&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1459765923323" class="sasNote"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1459765923323" class="sasNote"&gt;NOTE: There were 2 observations read from the data set WORK.HBP.&lt;/DIV&gt;
&lt;DIV id="sasLogWarning1_1459765923323" class="sasWarning"&gt;WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 1 observations and 8 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1459765923323" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Do you have the same error?&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Apr 2016 10:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261041#M2049</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-04T10:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261043#M2050</link>
      <description>&lt;P&gt;Yeah, have to safeguard because SAS does not stop evaluating a boolean "and" when the first false condition is encountered.&lt;/P&gt;
&lt;P&gt;Improved code with test data&amp;amp;colon;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Hbp1 Hbp2 Hbp3 Hbp4 Hbp5;
cards;
1 0 0 0 0 1
2 0 0 0 . .
3 0 . . 0 .
4 0 0 1 1 1
5 0 . 0 . 1
6 0 . 1 . .
;
run;

data want;
set have;
array hbp {*} hbp1-hbp5;
i = 1;
do while (i &amp;lt;= dim(hbp) and person_years = .);
  if hbp{i} = 1 or i = dim(hbp) then person_years = i - .5;
  i + 1;
end;
drop i;
run;&lt;BR /&gt;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                                                                                         person_
                                    Obs    ID    Hbp1    Hbp2    Hbp3    Hbp4    Hbp5     years

                                     1      1      0       0       0       0       1       4.5  
                                     2      2      0       0       0       .       .       4.5  
                                     3      3      0       .       .       0       .       4.5  
                                     4      4      0       0       1       1       1       2.5  
                                     5      5      0       .       0       .       1       4.5  
                                     6      6      0       .       1       .       .       2.5  
&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2016 10:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261043#M2050</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-04T10:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261050#M2051</link>
      <description>&lt;P&gt;Dear Kurt,&lt;/P&gt;
&lt;P&gt;I think the results should be like this:&lt;/P&gt;
&lt;PRE&gt;                                    Obs    ID    Hbp1    Hbp2    Hbp3    Hbp4    Hbp5     expect_results   your_results

                                     1      1      0       0       0       0       1       4.5                 4.5
                                     2      2      0       0       0       .       .       3.5                 4.5
                                     3      3      0       .       .       0       .       4.5                 4.5
                                     4      4      0       0       1       1       1       2.5                 2.5
                                     5      5      0       .       0       .       1       4                   4.5
                                     6      6      0       .       1       .       .       2                   2.5&lt;/PRE&gt;
&lt;P&gt;ID 2 can not have the same result as ID 1. It should be 3.5&lt;/P&gt;
&lt;P&gt;ID 5 has 1 missing value before the last observation (Hbp5) and this last obs=1, so person_years=3 years (from Hbp1 to hbp3) + 1 year (1/2 length of time from Hbp3 to Hbp5 or 2 years, 'cause of the missing value in year 4_Hbp4).&lt;/P&gt;
&lt;P&gt;ID 6&amp;nbsp;&lt;SPAN&gt;has 1 missing value before the last observation (Hbp3) and this&amp;nbsp; last obs=1, so&amp;nbsp;so person_years=1 years (1/2 length of time from Hbp1 to hbp3 or 2 years).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Perhaps I should clarify my rule again:&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Missing values before Observation with value 0 are consider 0 (so we count this year=1)&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Missing values before Observation with value 1 are still missing values. (so person_years will be 1/2 length of time from the last obs before missing value to the first obs with value 1)&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;Can you help me adjust the code to produce the results for the above conditions? I could not work it out.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 11:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261050#M2051</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-04T11:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261055#M2052</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52943"&gt;@Minhtrang&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Dear Kurt,&lt;/P&gt;
&lt;P&gt;I think the results should be like this:&lt;/P&gt;
&lt;PRE&gt;                                    Obs    ID    Hbp1    Hbp2    Hbp3    Hbp4    Hbp5     expect_results   your_results

                                     1      1      0       0       0       0       1       4.5                 4.5
                                     2      2      0       0       0       .       .       3.5                 4.5
                                     3      3      0       .       .       0       .       4.5                 4.5
                                     4      4      0       0       1       1       1       2.5                 2.5
                                     5      5      0       .       0       .       1       4                   4.5
                                     6      6      0       .       1       .       .       2                   2.5&lt;/PRE&gt;
&lt;P&gt;ID 2 can not have the same result as ID 1. It should be 3.5&lt;/P&gt;
&lt;P&gt;ID 5 has 1 missing value before the last observation (Hbp5) and this last obs=1, so person_years=3 years (from Hbp1 to hbp3) + 1 year (1/2 length of time from Hbp3 to Hbp5 or 2 years, 'cause of the missing value in year 4_Hbp4).&lt;/P&gt;
&lt;P&gt;ID 6&amp;nbsp;&lt;SPAN&gt;has 1 missing value before the last observation (Hbp3) and this&amp;nbsp; last obs=1, so&amp;nbsp;so person_years=1 years (1/2 length of time from Hbp1 to hbp3 or 2 years).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Perhaps I should clarify my rule again:&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Missing values before Observation with value 0 are consider 0 (so we count this year=1)&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Missing values before Observation with value 1 are still missing values. (so person_years will be 1/2 length of time from the last obs before missing value to the first obs with value 1)&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;Can you help me adjust the code to produce the results for the above conditions? I could not work it out.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Check your rules again. Per your rules, ID 2 would get a virtual "1" in hbp5 and a missing value in hbp4, so the time between hbp3 and hbp5 would be two years, half that is 1 year, add to 3 means 4 years.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 12:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261055#M2052</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-04T12:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261067#M2053</link>
      <description>&lt;P&gt;Dear Kurt,&lt;/P&gt;
&lt;P&gt;I'm sorry that my English is not good enough so that my explanation was confusing.&lt;/P&gt;
&lt;P&gt;For ID 2, he was followed up for 3 years (from hbp1 to hbp3, if hbp2 is missing, I still consider it as hbp2=0). Information on hbp4 and hbp5 is missing due to drop out or loss to follow-up, so I just add 0.5 year. Finally, the person_years for this ID is 3.5.&lt;/P&gt;
&lt;P&gt;Maybe I should ajust my rule as:&lt;/P&gt;
&lt;P&gt;Any missing value between 0...0 is considered as 0&lt;/P&gt;
&lt;P&gt;Any missing value between 0..1 stays the same as missing, and the person_years for this period=1/2 length of time from 0..to..1 (ex: hbp2...hbp5: 1/2 length of time is 1.5 years)&lt;/P&gt;
&lt;P&gt;I hope you can understand my explanation this time and help me adjust for the code.&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 12:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261067#M2053</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-04T12:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261077#M2054</link>
      <description>&lt;P&gt;But for ID2, there are TWO years from hbp3 to hbp5 (5 minus 3), and half of that is ONE year. 3 + 1 = 4.&lt;/P&gt;
&lt;P&gt;Your value of 3.5 for ID 2 contradicts your example in&lt;/P&gt;
&lt;P&gt;"Any missing value between 0..1 stays the same as missing, and the person_years for this period=1/2 length of time from 0..to..1 (ex: hbp2...hbp5: 1/2 length of time is 1.5 years)"&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 13:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261077#M2054</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-04T13:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261090#M2055</link>
      <description>&lt;P&gt;Dear Kurt,&lt;/P&gt;
&lt;P&gt;ID 2 has Hbp3 (value 0) Hbp4 (missing value) Hbp5 (missing value): 0 . .&lt;/P&gt;
&lt;P&gt;So it's not the case "any missing value between 0..1" but between "0....until the last observation which is also a missing value"&lt;/P&gt;
&lt;P&gt;Hbp5 has a missing value, not 1.&lt;/P&gt;
&lt;P&gt;Anyway, thank you very much for your help. I will try to write the code, maybe a simplebut very long code.&lt;/P&gt;
&lt;P&gt;I still hope to hear from your solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 13:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261090#M2055</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-04T13:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261273#M2056</link>
      <description>&lt;P&gt;Dear Kurt,&lt;/P&gt;
&lt;P&gt;I worked it out, thanks to some hint from your code (array and loop). My code is like this:&lt;/P&gt;
&lt;P&gt;*hbp1-hbp5: hypertension from visit 1 to 5;&lt;/P&gt;
&lt;P&gt;*hp: hypertension after 5 year follow-up;&lt;/P&gt;
&lt;P&gt;*year1: last visit with hbp=0 if hp=0;&lt;/P&gt;
&lt;P&gt;*incvisit: visit with incidence hypertension;&lt;/P&gt;
&lt;P&gt;*lastzero:&amp;nbsp;&lt;SPAN&gt;last visit with hbp=0 before incvisit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;*personyear: person-years;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;data hbp;&lt;BR /&gt;input id hbp1 hbp2 hbp3 hbp4 hbp5 hp;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 0 0 0 1 1&lt;BR /&gt;2 0 0 0 . . 0&lt;BR /&gt;3 0 . . 0 . 0&lt;BR /&gt;4 0 0 1 1 1 1&lt;BR /&gt;5 0 . 0 . 1 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set hbp;&lt;BR /&gt;array hbp {*} hbp1-hbp5;&lt;BR /&gt;i = 1;&lt;BR /&gt;do while (hp=0 and i&amp;lt;=dim(hbp));&lt;BR /&gt;if missing(hbp{i})=0 then year1=i;&lt;BR /&gt;i+1;&lt;BR /&gt;end;&lt;BR /&gt;do while (hp=1 and i&amp;lt;=dim(hbp) and incvisit=.);&lt;BR /&gt;if hbp{i}=1 then incvisit=i;&lt;BR /&gt;i+1;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want1;&lt;BR /&gt;set want;&lt;BR /&gt;array hbp {*} hbp1-hbp5;&lt;BR /&gt;i = 1;&lt;BR /&gt;do while (hp=1 and i&amp;lt;=incvisit);&lt;BR /&gt;if hbp{i}=0 then lastzero=i;&lt;BR /&gt;i+1;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want2;&lt;BR /&gt;set want1;&lt;BR /&gt;if hp=0 then personyear=year1;&lt;BR /&gt;else personyear=lastzero+(incvisit-lastzero)/2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result with variable "personyear":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD width="35"&gt;
&lt;P&gt;&lt;STRONG&gt;Obs&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="21"&gt;
&lt;P&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;&lt;STRONG&gt;hbp1&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;&lt;STRONG&gt;hbp2&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;&lt;STRONG&gt;hbp3&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;&lt;STRONG&gt;hbp4&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;&lt;STRONG&gt;hbp5&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="25"&gt;
&lt;P&gt;&lt;STRONG&gt;hp&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="44"&gt;
&lt;P&gt;&lt;STRONG&gt;year1&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="54"&gt;
&lt;P&gt;&lt;STRONG&gt;incvisit&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58"&gt;
&lt;P&gt;&lt;STRONG&gt;lastzero&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="80"&gt;
&lt;P&gt;&lt;STRONG&gt;personyear&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="35"&gt;
&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="21"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="25"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="44"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="54"&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="80"&gt;
&lt;P&gt;4.5&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="35"&gt;
&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="21"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="25"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="44"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="54"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="80"&gt;
&lt;P&gt;3.0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="35"&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="21"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="25"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="44"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="54"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="80"&gt;
&lt;P&gt;4.0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="35"&gt;
&lt;P&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="21"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="25"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="44"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="54"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="80"&gt;
&lt;P&gt;2.5&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="35"&gt;
&lt;P&gt;&lt;STRONG&gt;5&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="21"&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="41"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="25"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="44"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="54"&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="80"&gt;
&lt;P&gt;4.0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 05 Apr 2016 03:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261273#M2056</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-05T03:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261278#M2057</link>
      <description>&lt;PRE&gt;
It is the kind of hard to understand what you are expected.
Assuming I know what you mean.



data have;
input ID Hbp1 Hbp2 Hbp3 Hbp4 Hbp5;
cards;
1 0 0 0 0 1
2 0 0 0 . .
3 0 . . 0 .
4 0 0 1 1 1
5 0 . 0 . 1
6 0 . 1 . .
;
run;


data want;
 if _n_=1 then do;
  declare hash h();
  h.definekey('k');
  h.definedone();
 end;
set have;
array x{*} Hbp:;
do i=dim(x) to 1 by -1;
 if x{i}=0 then leave;
 k=x{i};h.replace();
end;
person_year=i+0.5*h.num_items;
h.clear();
drop k i;
run;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Apr 2016 05:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261278#M2057</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-05T05:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on SAS code for calculating survival follow up time (person years)</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261314#M2058</link>
      <description>&lt;P&gt;Dear Xia,&lt;/P&gt;
&lt;P&gt;I'm really surprised by your code! It's so short and it creates the same results which I expected.&lt;/P&gt;
&lt;P&gt;I've more experience now.&lt;/P&gt;
&lt;P&gt;Thank you very much.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 09:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Need-help-on-SAS-code-for-calculating-survival-follow-up-time/m-p/261314#M2058</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-05T09:38:41Z</dc:date>
    </item>
  </channel>
</rss>

