JFerron Tracker
https://communities.sas.com/kntur85557/tracker
JFerron TrackerSun, 08 Sep 2024 22:44:11 GMT2024-09-08T22:44:11ZRe: Transforming Long Data with Nested Counts - Help!
https://communities.sas.com/t5/SAS-Programming/Transforming-Long-Data-with-Nested-Counts-Help/m-p/817349#M322637
<P>I could not get this code to count abstinence intervals. It just counts weekly or daily intervals (whichever I denote as my day variable). Here is my code:</P><P>I have renamed (weekstartdate to date and created a daily variable).<BR />data want2 (drop=date day);<BR />do until (last.abs_yes);<BR />set counting_dates;<BR />retain day 1;<BR />by id date abs_yes notsorted;<BR />if first.abs_yes then do;<BR />beg_date= date + day-1;<BR />end;<BR />end;<BR />end_date=date+day-1;<BR />format beg_date end_date mmddyy10.;<BR />run;</P><P><BR />proc print data=want2 (obs =100);<BR />RUN;</P><P> </P><P>Can you help? I'm just not sure what I'm doing wrong. It runs, I'm just not getting the same output.</P>Thu, 09 Jun 2022 19:08:28 GMThttps://communities.sas.com/t5/SAS-Programming/Transforming-Long-Data-with-Nested-Counts-Help/m-p/817349#M322637JFerron2022-06-09T19:08:28ZRe: Transforming Long Data with Nested Counts - Help!
https://communities.sas.com/t5/SAS-Programming/Transforming-Long-Data-with-Nested-Counts-Help/m-p/817347#M322635
<P>First, I would like to say thank you for your response. I probably mis-communicated the problem so, the output that I am getting is not quite right. It was giving me weekly output with abstinence marked. What I would like to do is to add the counter (labelled abs_yes) by whether it's on or off (1 vs 0) but sequentially. So for example, if the person has 2 days of off (abs_yes = 0), it would look like this:</P><DIV class=""><DIV><DIV align="center">Obs id Abs start ends eventstart123 <TABLE cellspacing="0" cellpadding="5"><TBODY><TR><TD>700</TD><TD>0</TD><TD>0</TD><TD>2</TD><TD>01/21/2013</TD></TR><TR><TD>700</TD><TD>1</TD><TD>2</TD><TD>15</TD><TD>01/23/2013</TD></TR><TR><TD>700</TD><TD>0</TD><TD>15</TD><TD>17</TD><TD>01/25/2013</TD></TR></TBODY></TABLE><P>In this example, I have recoded abs_yes to abs (in order to not change any variable names, per your suggestion). I'm assuming this requires some sort of lag function where I would track how many sequential days are on or off on the original (abs_yes)? If it helps, the eventstart variable is less important than the start and ends variable, which count the number of sequential days abstinence or smoking within an individual.</P></DIV></DIV></DIV>Thu, 09 Jun 2022 18:48:58 GMThttps://communities.sas.com/t5/SAS-Programming/Transforming-Long-Data-with-Nested-Counts-Help/m-p/817347#M322635JFerron2022-06-09T18:48:58ZTransforming Long Data with Nested Counts - Help!
https://communities.sas.com/t5/SAS-Programming/Transforming-Long-Data-with-Nested-Counts-Help/m-p/816957#M322490
<P>Hello!</P><P>I'm struggling with a data transformation where I have about a years worth of days, 600 or so participants, and dates at the beginning of each week (always starting on Monday). It looks like this:</P><TABLE><TBODY><TR><TD>id</TD><TD>weekstartdate</TD><TD>day</TD><TD>Abs_yes</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>1</TD><TD>0</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>2</TD><TD>0</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>3</TD><TD>0</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>4</TD><TD>0</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>5</TD><TD>1</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>6</TD><TD>1</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>7</TD><TD>1</TD></TR><TR><TD>808</TD><TD>1/10/2022</TD><TD>1</TD><TD>0</TD></TR><TR><TD>808</TD><TD>1/10/2022</TD><TD>2</TD><TD>0</TD></TR><TR><TD>808</TD><TD>1/10/2022</TD><TD>3</TD><TD>0</TD></TR><TR><TD>808</TD><TD>1/10/2022</TD><TD>4</TD><TD>1</TD></TR></TBODY></TABLE><P> </P><P>I am trying to get my output dataset so it can be used for a recurrent event survival analysis and it would count each event (abs_yes = 1) and non (event (abs_yes = 1) within the individual where there are events (even as few as 1 in a row). I currently only have the start date of each week (which are consecutive and would also like to output the beginning date (weekstartdate) of each event. In the example below, the abs_yes variable serves as an indicator for the length of the episode.</P><TABLE><TBODY><TR><TD>id</TD><TD>weekstartdate</TD><TD>Abs_yes</TD><TD>start</TD><TD>ends</TD></TR><TR><TD>808</TD><TD>1/3/2022</TD><TD>0</TD><TD>0</TD><TD>4</TD></TR><TR><TD>808</TD><TD>1/7/2022</TD><TD>1</TD><TD>4</TD><TD>7</TD></TR><TR><TD>808</TD><TD>1/10/2022</TD><TD>0</TD><TD>7</TD><TD>10</TD></TR><TR><TD>808</TD><TD>1/13/2022</TD><TD>0</TD><TD>10</TD><TD>11</TD></TR></TBODY></TABLE><P> </P><P>I have had many false starts using nested do-loops. This data had been a wide file with days of abstinence by week across the row. So, I have gotten the data closer to the objective but am not sure how to get the program to repeat a count within an id (I can get it to count how many abs_yes within each id but not length in days of episode).</P><P>I would really appreciate any help/tips that I can get!</P><P>Thanks,</P><P>Joelle</P>Tue, 07 Jun 2022 20:09:46 GMThttps://communities.sas.com/t5/SAS-Programming/Transforming-Long-Data-with-Nested-Counts-Help/m-p/816957#M322490JFerron2022-06-07T20:09:46Z