<?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: Counting gaps in days and rolling up to individual level in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452972#M13975</link>
    <description>&lt;P&gt;Can you please post a sample of your expected output?&lt;/P&gt;</description>
    <pubDate>Tue, 10 Apr 2018 21:38:42 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-04-10T21:38:42Z</dc:date>
    <item>
      <title>Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452971#M13974</link>
      <description>&lt;P&gt;I have a data-set with individual id, date variable for each day, and a filled date variable, as shown below. I wanted to know the gaps in filled dates, so I created a count variable which starts as 1 on the first gap for each gap interval and then increments by 1. I would now like to create an id -level data-set (one observation per person) with indicator variables for number of gaps within each gap interval (for instance, Jan 3 to Jan 5, 3 days gap, and Jan 8 to Jan 9, 2 days gap - for id A). How could I do this? Thank you!&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;each date&lt;/TD&gt;&lt;TD&gt;filled date&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1-Jan&lt;/TD&gt;&lt;TD&gt;1-Jan&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2-Jan&lt;/TD&gt;&lt;TD&gt;2-Jan&l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
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452971#M13974</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-04-10T21:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452972#M13975</link>
      <description>&lt;P&gt;Can you please post a sample of your expected output?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 21:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452972#M13975</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-10T21:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452985#M13977</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the variable COUNT already in your data set, or do you need the program to compute it as well?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 22:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452985#M13977</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-10T22:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452986#M13978</link>
      <description>&lt;P&gt;Something like this would work (I want how many days were continuously filled and how many continuous gap intervals). Thank you!&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;each date&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1-Jan&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3-Jan&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;6-Jan&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;8-Jan&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 22:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452986#M13978</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-04-10T22:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452987#M13979</link>
      <description>&lt;P&gt;I created that variable to count the continuous gaps, so it is currently on the data-set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 22:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452987#M13979</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-04-10T22:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452991#M13981</link>
      <description>&lt;P&gt;Here's a start:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;where count &amp;gt; 0;&lt;/P&gt;
&lt;P&gt;if first.id then group=1;&lt;/P&gt;
&lt;P&gt;else if count=1 then group + 1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That creates an artificial GROUP variable that can identify when groups of observations having count &amp;gt; 0 begin and end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id group;&lt;/P&gt;
&lt;P&gt;if last.group;&lt;/P&gt;
&lt;P&gt;drop group;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's closer to what you asked for.&amp;nbsp; It gives you the last observation in each grouping.&amp;nbsp; Take a look at that much, and then reconsider.&amp;nbsp; Trying to change this into one observation per ID is a bad idea.&amp;nbsp; You will end up with different numbers of variables populated for each ID, and the structure of the data will be difficult to program with.&amp;nbsp; But if you still want to pursue that as the final result, it can be done using PROC TRANSPOSE (perhaps more than one PROC TRANSPOSE depending on what you want the final result to look like).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;********** EDITED:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While I was composing this,&amp;nbsp; you must have posted what you want the result to look like.&amp;nbsp; I may be able to get to that later, to include some of the "0" records.&amp;nbsp; Right now, all you get is the non-zero gaps.&amp;nbsp; But that will have to wait (at least for me).&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 22:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452991#M13981</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-10T22:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452997#M13982</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (ID	each_date	filled_date) ($)	count;
datalines;
A	1-Jan	1-Jan	0
A	2-Jan	2-Jan	0
A	3-Jan	.	1
A	4-Jan	.	2
A	5-Jan	.	3
A	6-Jan	6-Jan	0
A	7-Jan	7-Jan	0
A	8-Jan	.	1
A	9-Jan	.	2
A	10-Jan	10-Jan	0
;
data temp;
set have;
by id ;
if first.id then k=0;
if count=1 or count=0 and lag(count) ne 0 then k+1;
run;

proc sql;
create table want as
select id,each_date,max(count) as _count
from temp
group by id, k
having each_date=min(each_date) and count(k)&amp;gt;1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 23:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/452997#M13982</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-10T23:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Counting gaps in days and rolling up to individual level</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/453211#M13986</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (ID	each_date	filled_date) ($)	count;
datalines;
A	1-Jan	1-Jan	0
A	2-Jan	2-Jan	0
A	3-Jan	.	1
A	4-Jan	.	2
A	5-Jan	.	3
A	6-Jan	6-Jan	0
A	7-Jan	7-Jan	0
A	8-Jan	.	1
A	9-Jan	.	2
A	10-Jan	10-Jan	0
;
data have;
 set have;
 flag=missing(filled_date);
run;
data have;
 set have;
 by id flag notsorted;
 group+first.flag;
run;
data want;
 do until(last.group);
   set have;
   by group;
   if first.group then new_date=each_date;
 end;
 drop each_date	filled_date group flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Apr 2018 13:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-gaps-in-days-and-rolling-up-to-individual-level/m-p/453211#M13986</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-04-11T13:46:46Z</dc:date>
    </item>
  </channel>
</rss>

