<?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: Person time per person per year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794838#M254885</link>
    <description>That makes sense. Thanks!</description>
    <pubDate>Mon, 07 Feb 2022 17:08:21 GMT</pubDate>
    <dc:creator>reemm225</dc:creator>
    <dc:date>2022-02-07T17:08:21Z</dc:date>
    <item>
      <title>Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794792#M254863</link>
      <description>&lt;P&gt;I have a dataset where I have multiple rows per id, covariates for each id, year of prescription (yearrx), and study start (ss) and study end (se). I want to calculate the total person time donated be each member. What I eventually want to have is 2 rows per id, so that in the first row, I will sum the person time from the study start (ss) until the end of that year, and a second row that will sum the person time one day after the end of the study start year, until the end of the study.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example patient 2, entered the study In may,2,2001, had 2 prescription types in 2019, and left the study at June,30,2019. I want to create for this patient 2 rows, the first row with the time between SS and end of ss(12,31,year(SS)), and a second row calculating the time between (01,01,year(SS)+1), and the end of the study (SE).&amp;nbsp; I previously tried to calculate the person time in each row but it didn't work, any thoughts? This codes creates columns, but I want two rows per patient at the end.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data x; set try2;
d1= intck('day', ss, mdy(12,31, year(ss)));
d2= intck('day', mdy(1,1,(year(ss)+1)), se);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&g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&gt;1&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;z&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;06-Aug-12&lt;/TD&gt;&lt;TD&gt;30-Jun-19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;v&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;02-May-01&lt;/TD&gt;&lt;TD&gt;30-Jun-19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;v&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;02-May-01&lt;/TD&gt;&lt;TD&gt;30-Jun-19&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 07 Feb 2022 14:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794792#M254863</guid>
      <dc:creator>reemm225</dc:creator>
      <dc:date>2022-02-07T14:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794794#M254864</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x; 
    set try2;
    d1= intck('day', ss, mdy(12,31, year(ss)));
    output;
    d1= intck('day', mdy(1,1,(year(ss)+1)), se);
    output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Feb 2022 14:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794794#M254864</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-07T14:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794815#M254871</link>
      <description>&lt;P&gt;I don't understand why you have the other variable and the multiple observations.&lt;/P&gt;
&lt;P&gt;So let's ignore them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id cov1 $ cov2 $ RxYear type NRx SS :date. SE :date. ;
  format ss se date9.;
cards;
1 x z 2012 2 4 06-Aug-12 30-Jun-19
1 x z 2013 2 8 06-Aug-12 30-Jun-19
1 x z 2014 2 8 06-Aug-12 30-Jun-19
1 x z 2015 2 6 06-Aug-12 30-Jun-19
1 x z 2016 2 5 06-Aug-12 30-Jun-19
2 y v 2019 1 1 02-May-01 30-Jun-19
2 y v 2019 2 1 02-May-01 30-Jun-19
;

proc sort data=have(keep=id ss se)  out=subjects nodupkey;
  by id ;
run;

data want;
  set subjects;
  if year(se)=year(ss) then do;
    year1=1;
    rest=1;
    duration=se-ss;
    output;
  end;
  else do;
    year1=1;
    rest=0;
    duration = mdy(1,1,year(ss)+1)-ss;
    output;
    year1=0;
    rest=1;
    duration = se - mdy(1,1,year(ss)+1);
    output;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    id           SS           SE    year1    rest    duration

 1      1    06AUG2012    30JUN2019      1        0        148
 2      1    06AUG2012    30JUN2019      0        1       2371
 3      2    02MAY2001    30JUN2019      1        0        244
 4      2    02MAY2001    30JUN2019      0        1       6389
&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Feb 2022 15:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794815#M254871</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-07T15:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794817#M254872</link>
      <description>&lt;P&gt;Perhaps you meant to generate a separate observation per year?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set subjects;
  do year=year(ss) to year(se);
    duration = min(se,mdy(12,31,year)) - max(ss,mdy(1,1,year)) + 1;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    id           SS           SE    year    duration

  1     1    06AUG2012    30JUN2019    2012       148
  2     1    06AUG2012    30JUN2019    2013       365
  3     1    06AUG2012    30JUN2019    2014       365
  4     1    06AUG2012    30JUN2019    2015       365
  5     1    06AUG2012    30JUN2019    2016       366
  6     1    06AUG2012    30JUN2019    2017       365
  7     1    06AUG2012    30JUN2019    2018       365
  8     1    06AUG2012    30JUN2019    2019       181
  9     2    02MAY2001    30JUN2019    2001       244
 10     2    02MAY2001    30JUN2019    2002       365
 11     2    02MAY2001    30JUN2019    2003       365
 12     2    02MAY2001    30JUN2019    2004       366
 13     2    02MAY2001    30JUN2019    2005       365
 14     2    02MAY2001    30JUN2019    2006       365
 15     2    02MAY2001    30JUN2019    2007       365
 16     2    02MAY2001    30JUN2019    2008       366
 17     2    02MAY2001    30JUN2019    2009       365
 18     2    02MAY2001    30JUN2019    2010       365
 19     2    02MAY2001    30JUN2019    2011       365
 20     2    02MAY2001    30JUN2019    2012       366
 21     2    02MAY2001    30JUN2019    2013       365
 22     2    02MAY2001    30JUN2019    2014       365
 23     2    02MAY2001    30JUN2019    2015       365
 24     2    02MAY2001    30JUN2019    2016       366
 25     2    02MAY2001    30JUN2019    2017       365
 26     2    02MAY2001    30JUN2019    2018       365
 27     2    02MAY2001    30JUN2019    2019       181
&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Feb 2022 15:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794817#M254872</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-07T15:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794826#M254877</link>
      <description>Yes that is what I wanted, but I though to just create 2 rows per patient. fist year and then lump the rest. Thank you!!</description>
      <pubDate>Mon, 07 Feb 2022 16:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794826#M254877</guid>
      <dc:creator>reemm225</dc:creator>
      <dc:date>2022-02-07T16:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794828#M254879</link>
      <description>Thank you. This code now multiplies each id data, is there a way to keep just the number of rows per id per year?</description>
      <pubDate>Mon, 07 Feb 2022 16:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794828#M254879</guid>
      <dc:creator>reemm225</dc:creator>
      <dc:date>2022-02-07T16:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794832#M254881</link>
      <description>&lt;P&gt;SHow us the desired output.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 16:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794832#M254881</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-07T16:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794834#M254882</link>
      <description>&lt;P&gt;Which is it?&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="Screenshot 2022-02-07 114226.jpg" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68258i02D8E0C3C9D1B854/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-02-07 114226.jpg" alt="Screenshot 2022-02-07 114226.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you do not want to change the number of observations use something like your original code where you have one variable for the first year and another for the "rest".&amp;nbsp; Otherwise if you want to output separate observations for the first year and the rest then by definition you are going to have multiple observations.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 16:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794834#M254882</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-07T16:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794838#M254885</link>
      <description>That makes sense. Thanks!</description>
      <pubDate>Mon, 07 Feb 2022 17:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794838#M254885</guid>
      <dc:creator>reemm225</dc:creator>
      <dc:date>2022-02-07T17:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Person time per person per year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794848#M254888</link>
      <description>This worked this is very helpful!!!</description>
      <pubDate>Mon, 07 Feb 2022 17:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Person-time-per-person-per-year/m-p/794848#M254888</guid>
      <dc:creator>reemm225</dc:creator>
      <dc:date>2022-02-07T17:48:03Z</dc:date>
    </item>
  </channel>
</rss>

