05-15-2020
ChrisCarroll
Calcite | Level 5
Member since
05-11-2020
- 4 Posts
- 0 Likes Given
- 0 Solutions
- 0 Likes Received
-
Latest posts by ChrisCarroll
Subject Views Posted 789 05-13-2020 07:46 AM 808 05-13-2020 07:29 AM 613 05-11-2020 02:54 PM 668 05-11-2020 01:21 PM -
Activity Feed for ChrisCarroll
- Posted Re: Grouping contemporary groups on SAS Programming. 05-13-2020 07:46 AM
- Posted Grouping contemporary groups on SAS Programming. 05-13-2020 07:29 AM
- Posted Re: Grouping observations by days apart on New SAS User. 05-11-2020 02:54 PM
- Posted Grouping observations by days apart on New SAS User. 05-11-2020 01:21 PM
05-13-2020
07:46 AM
Apologies, once the edit has been carried out, there can then be more than 5 in the one contemporary group.
... View more
05-13-2020
07:29 AM
Hi, I am trying to make a new variable grouping contemporary groups. I would like to group contemporary groups where the count of the group (count variable) is less than 5 observations only. As you can see the startdate for each group is the earliest observation according to the start_lactation variable and the enddate for each group is the last observation according to the start_lactation variable. I would only like to add contemporary groups together if the number of days between startdate and enddate of the contemporary group is less than 150 days after the new contemporary group has been added. Once a new contemporary group is added the startdate or enddate of that group would change and become the value according to the start_lactation date of the new contemporary group added. To emphasise, if a contemporary group would be added to another group and the number of days between the startdate and enddate is greater than 150 days then it should not be added. Contemporary groups of lower than 5 observaions can join any size group once they fit the conditions mentioned above. In the case of the data below I would like observations 1-7 in the one contemporary group, with the startdate of this group the same (05/02/2011) and the new enddate as 20/04/2011. Observation 8 and 9 should not be added to any other contemporary group,as if it was added to group 1 the startdate would be 05/02/2011 and the enddate would be 14/10/2011 which is more than 150 days and if it were added to contemporary group 6 then the startdate would be 08/10/2011 and the enddate would be 15/03/12 which is more than 150 days. Nothing should happen to contemporary group 6 as the count here is more than 5. I am quite a novice when it come to SAS so an explanation would be brilliant. Any help is greatly appreciated. I am using SAS9.4. Thanks in advance data WORK.TWOHERDS1; infile datalines dsd truncover; input TECHID:13. START_LACTATION:DDMMYY10. contemporarygroup:32. startdate:DDMMYY. enddate:DDMMYY. count:32.; format TECHID 13. START_LACTATION DDMMYY10. startdate DDMMYY. enddate DDMMYY.; label TECHID="TECHID"; datalines; 669222149 05/02/2011 1 05/02/11 10/02/11 4 669222145 05/02/2011 1 05/02/11 10/02/11 4 669222150 08/02/2011 1 05/02/11 10/02/11 4 669823432 10/02/2011 1 05/02/11 10/02/11 4 671847527 21/02/2011 2 21/02/11 21/02/11 1 669819685 17/03/2011 3 17/03/11 17/03/11 1 669819684 20/04/2011 4 20/04/11 20/04/11 1 669222144 08/10/2011 5 08/10/11 14/10/11 2 676229644 14/10/2011 5 08/10/11 14/10/11 2 748982347 25/01/2012 6 25/01/12 15/03/12 49 748982346 25/01/2012 6 25/01/12 15/03/12 49 744293316 26/01/2012 6 25/01/12 15/03/12 49 746731229 26/01/2012 6 25/01/12 15/03/12 49 748465662 27/01/2012 6 25/01/12 15/03/12 49 744813559 28/01/2012 6 25/01/12 15/03/12 49 ;;;;
... View more
05-11-2020
02:54 PM
Thanks that worked well. Is there a way of grouping the "group" column if there are less than 5 observations in any particular group and only if the group_start_date between the consecutive groups is less than 100 days. Thanks.
... View more
05-11-2020
01:21 PM
Hi all, I'm currently attempting to group observations where the days between observations is less than 10. The new column can be called group. I would like the title of the observations in a group to be the earliest date according to start_lactation. In the case of the data below, I would like observations 1-4 with the group column titled as 05/02/2011. Observations 5-7 should be left as blank. Observations 8 and 9 should be titled as 08/10/2011. Observations 10-15 should be titled as 25/01/2012. I need to do this for thousands of observations. I'm using sas 9.4. Any help is greatly appreciated data WORK.X; infile datalines dsd truncover; input TECHID:13. START_LACTATION:DDMMYY10. Daysapart:32.; format TECHID 13. START_LACTATION DDMMYY10.; label TECHID="TECHID"; datalines; 669222149 05/02/2011 . 669222145 05/02/2011 0 669222150 08/02/2011 3 669823432 10/02/2011 2 671847527 21/02/2011 11 669819685 17/03/2011 24 669819684 20/04/2011 34 669222144 08/10/2011 171 676229644 14/10/2011 6 748982347 25/01/2012 103 748982346 25/01/2012 0 744293316 26/01/2012 1 746731229 26/01/2012 0 748465662 27/01/2012 1 744813559 28/01/2012 1
... View more