<?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: Deleting incomplete time series within panel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646146#M193248</link>
    <description>&lt;P&gt;In a single data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ YEAR EARN;
datalines;
1       1960      450
1       1961      310
1       1962      529
2       1978      10
2       1979      15
2       1980      8
2       1982      10
3       1972      1000
3       1973      1599
;

data want;
set have;
del = 0;
old_year = .;
do until (last.ID);
  set have;
  by ID;
  if not first.ID and year - old_year &amp;gt; 1 then del = 1;
  old_year = year;
end;
do until (last.ID);
  set have;
  by ID;
  if not del then output;
end;
drop old_year del;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how the input dataset is presented in a data step with datalines; this leaves no doubts about contents, variable types and other attributes. Please do so in the future.&lt;/P&gt;</description>
    <pubDate>Fri, 08 May 2020 10:12:14 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-08T10:12:14Z</dc:date>
    <item>
      <title>Deleting incomplete time series within panel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646135#M193245</link>
      <description>&lt;P&gt;I have a panel of the following structure:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YEAR&amp;nbsp;&amp;nbsp;&amp;nbsp; EARN&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1960&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 450&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1961&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 310&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1962&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 529&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1978&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1979&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1980&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1982&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1972&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1973 &amp;nbsp; &amp;nbsp;&amp;nbsp; 1599 &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to delete every ID, for which the time series is incomplete. In this case, this is ID 2, since 1981 is missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not yet very familiar with SAS and I can not come up with a method. I would appreciate help on this. Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 09:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646135#M193245</guid>
      <dc:creator>shenflow</dc:creator>
      <dc:date>2020-05-08T09:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting incomplete time series within panel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646145#M193247</link>
      <description>&lt;P&gt; &lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254635"&gt;@shenflow&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID YEAR EARN;
	datalines;
1       1960      450
1       1961      310
1       1962      529
2       1978      10
2       1979      15
2       1980      8
2       1982      10
3       1972      1000
3       1973      1599
;
run;

/* Identify ID to exclude form the input dataset */
data list_exclude (keep=ID);
	do until (last.ID);
		set have;
		by ID;
		_lag = lag(YEAR) + 1;
		if first.ID then call missing(_lag);
		if not missing(_lag) and _lag ne YEAR then output;
	end;
run;

/* Remove ID belonging to the previous list */
proc sql;
	select *
	from have
	where ID not in (select * from list_exclude);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; background-color: #f5f5f5;"&gt;Output:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-05-08 à 12.03.03.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39209i9C745FC993A045A5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-05-08 à 12.03.03.png" alt="Capture d’écran 2020-05-08 à 12.03.03.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;All the best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 10:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646145#M193247</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-08T10:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting incomplete time series within panel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646146#M193248</link>
      <description>&lt;P&gt;In a single data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ YEAR EARN;
datalines;
1       1960      450
1       1961      310
1       1962      529
2       1978      10
2       1979      15
2       1980      8
2       1982      10
3       1972      1000
3       1973      1599
;

data want;
set have;
del = 0;
old_year = .;
do until (last.ID);
  set have;
  by ID;
  if not first.ID and year - old_year &amp;gt; 1 then del = 1;
  old_year = year;
end;
do until (last.ID);
  set have;
  by ID;
  if not del then output;
end;
drop old_year del;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how the input dataset is presented in a data step with datalines; this leaves no doubts about contents, variable types and other attributes. Please do so in the future.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 10:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646146#M193248</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-08T10:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting incomplete time series within panel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646156#M193252</link>
      <description>&lt;P&gt;Assuming there are not same years within a ID group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID YEAR EARN;
	datalines;
1       1960      450
1       1961      310
1       1962      529
2       1978      10
2       1979      15
2       1980      8
2       1982      10
3       1972      1000
3       1973      1599
;
run;
proc sql;
create table want as
select * from have
 group by id
  having range(year)+1=count(*)&lt;BR /&gt;   order by id,year ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 May 2020 11:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-incomplete-time-series-within-panel/m-p/646156#M193252</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-08T11:07:27Z</dc:date>
    </item>
  </channel>
</rss>

