<?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: Grouping observations by days apart in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646884#M22092</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328318"&gt;@ChrisCarroll&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could add a counter to track the number of observations per group? And then add another set of logic to analyze the data by groups to see if the 100 days between group starts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 May 2020 20:59:18 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-05-11T20:59:18Z</dc:date>
    <item>
      <title>Grouping observations by days apart</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646816#M22089</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.X;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input TECHID:13. START_LACTATION:DDMMYY10. Daysapart:32.;&lt;BR /&gt;format TECHID 13. START_LACTATION DDMMYY10.;&lt;BR /&gt;label TECHID="TECHID";&lt;BR /&gt;datalines;&lt;BR /&gt;669222149 05/02/2011 .&lt;BR /&gt;669222145 05/02/2011 0&lt;BR /&gt;669222150 08/02/2011 3&lt;BR /&gt;669823432 10/02/2011 2&lt;BR /&gt;671847527 21/02/2011 11&lt;BR /&gt;669819685 17/03/2011 24&lt;BR /&gt;669819684 20/04/2011 34&lt;BR /&gt;669222144 08/10/2011 171&lt;BR /&gt;676229644 14/10/2011 6&lt;BR /&gt;748982347 25/01/2012 103&lt;BR /&gt;748982346 25/01/2012 0&lt;BR /&gt;744293316 26/01/2012 1&lt;BR /&gt;746731229 26/01/2012 0&lt;BR /&gt;748465662 27/01/2012 1&lt;BR /&gt;744813559 28/01/2012 1&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 17:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646816#M22089</guid>
      <dc:creator>ChrisCarroll</dc:creator>
      <dc:date>2020-05-11T17:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations by days apart</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646818#M22090</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set x;
by techid start_lactation;*may need to presort your data;

retain group group_start_date;
if first.techid then do;
group=1; 
group_start_date = start_lactation;
end;
else if daysApart&amp;gt;10 then do;
  group+1; 
   group_start_date = start_lactation;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328318"&gt;@ChrisCarroll&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data WORK.X;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input TECHID:13. START_LACTATION:DDMMYY10. Daysapart:32.;&lt;BR /&gt;format TECHID 13. START_LACTATION DDMMYY10.;&lt;BR /&gt;label TECHID="TECHID";&lt;BR /&gt;datalines;&lt;BR /&gt;669222149 05/02/2011 .&lt;BR /&gt;669222145 05/02/2011 0&lt;BR /&gt;669222150 08/02/2011 3&lt;BR /&gt;669823432 10/02/2011 2&lt;BR /&gt;671847527 21/02/2011 11&lt;BR /&gt;669819685 17/03/2011 24&lt;BR /&gt;669819684 20/04/2011 34&lt;BR /&gt;669222144 08/10/2011 171&lt;BR /&gt;676229644 14/10/2011 6&lt;BR /&gt;748982347 25/01/2012 103&lt;BR /&gt;748982346 25/01/2012 0&lt;BR /&gt;744293316 26/01/2012 1&lt;BR /&gt;746731229 26/01/2012 0&lt;BR /&gt;748465662 27/01/2012 1&lt;BR /&gt;744813559 28/01/2012 1&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 17:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646818#M22090</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-11T17:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations by days apart</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646854#M22091</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 18:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646854#M22091</guid>
      <dc:creator>ChrisCarroll</dc:creator>
      <dc:date>2020-05-11T18:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations by days apart</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646884#M22092</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328318"&gt;@ChrisCarroll&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could add a counter to track the number of observations per group? And then add another set of logic to analyze the data by groups to see if the 100 days between group starts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 20:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-observations-by-days-apart/m-p/646884#M22092</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-11T20:59:18Z</dc:date>
    </item>
  </channel>
</rss>

