<?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 observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9243#M602</link>
    <description>data reduced;&lt;BR /&gt;
 do _n_=1 by 1 until( last.subject) ;&lt;BR /&gt;
   set your.data ;&lt;BR /&gt;
   by subject ;&lt;BR /&gt;
   if _n_ LE  4  then output ;&lt;BR /&gt;
 end;&lt;BR /&gt;
run;</description>
    <pubDate>Mon, 14 Feb 2011 10:56:45 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2011-02-14T10:56:45Z</dc:date>
    <item>
      <title>Deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9242#M601</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I want to keep only the four first observations for each subject in my data set. I have data which I have arranged by subjects and date, i.e. constructed as follows:&lt;BR /&gt;
&lt;BR /&gt;
Date      Subject       var&lt;BR /&gt;
17837       1            1000      &lt;BR /&gt;
17867       1            1100       &lt;BR /&gt;
17898       1            1050       &lt;BR /&gt;
17929       1            1200       &lt;BR /&gt;
17957       1            1200       &lt;BR /&gt;
17988       1            1250       &lt;BR /&gt;
18018       1            1150       &lt;BR /&gt;
17837       2            1000       &lt;BR /&gt;
17867       2            1100       &lt;BR /&gt;
17898       2            1050       &lt;BR /&gt;
17929       2            1200       &lt;BR /&gt;
17957       2            1200       &lt;BR /&gt;
17988       2            1250       &lt;BR /&gt;
18018       2            1150       &lt;BR /&gt;
&lt;BR /&gt;
What I want to do is to make a series where I keep only the first four&lt;BR /&gt;
observations for each subject, but drop the rest. Could someone please help&lt;BR /&gt;
me with a SAS code for such procedure?</description>
      <pubDate>Mon, 14 Feb 2011 09:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9242#M601</guid>
      <dc:creator>jossig</dc:creator>
      <dc:date>2011-02-14T09:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9243#M602</link>
      <description>data reduced;&lt;BR /&gt;
 do _n_=1 by 1 until( last.subject) ;&lt;BR /&gt;
   set your.data ;&lt;BR /&gt;
   by subject ;&lt;BR /&gt;
   if _n_ LE  4  then output ;&lt;BR /&gt;
 end;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 14 Feb 2011 10:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9243#M602</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-02-14T10:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9244#M603</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%let n=4;&lt;BR /&gt;
data selected;&lt;BR /&gt;
 input Date Subject var;&lt;BR /&gt;
 	cards;&lt;BR /&gt;
	17837 1 1000&lt;BR /&gt;
	17867 1 1100&lt;BR /&gt;
	17898 1 1050&lt;BR /&gt;
	17929 1 1200&lt;BR /&gt;
	17957 1 1200&lt;BR /&gt;
	17988 1 1250&lt;BR /&gt;
	18018 1 1150&lt;BR /&gt;
	17837 2 1000&lt;BR /&gt;
	17867 2 1100&lt;BR /&gt;
	17898 2 1050&lt;BR /&gt;
	17929 2 1200&lt;BR /&gt;
	17957 2 1200&lt;BR /&gt;
	17988 2 1250&lt;BR /&gt;
	1 3 1200&lt;BR /&gt;
	18018 2 1150&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=selected;&lt;BR /&gt;
	by subject date;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data selected;&lt;BR /&gt;
	set selected;&lt;BR /&gt;
		by subject date;&lt;BR /&gt;
	if first.subject then i=0;&lt;BR /&gt;
	i+1;&lt;BR /&gt;
	if i le &amp;amp;n then output;&lt;BR /&gt;
	drop i;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
A more complex example could be found at:&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/33/009.html" target="_blank"&gt;http://support.sas.com/kb/33/009.html&lt;/A&gt; &lt;BR /&gt;
&lt;BR /&gt;
Warm regards,&lt;BR /&gt;
Vasile</description>
      <pubDate>Mon, 14 Feb 2011 15:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9244#M603</guid>
      <dc:creator>Vasile01</dc:creator>
      <dc:date>2011-02-14T15:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9245#M604</link>
      <description>[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
 input Date Subject var ;&lt;BR /&gt;
cards;&lt;BR /&gt;
17837 1 1000&lt;BR /&gt;
17867 1 1100&lt;BR /&gt;
17898 1 1050&lt;BR /&gt;
17929 1 1200&lt;BR /&gt;
17957 1 1200&lt;BR /&gt;
17988 1 1250&lt;BR /&gt;
18018 1 1150&lt;BR /&gt;
17837 2 1000&lt;BR /&gt;
17867 2 1100&lt;BR /&gt;
17898 2 1050&lt;BR /&gt;
17929 2 1200&lt;BR /&gt;
17957 2 1200&lt;BR /&gt;
17988 2 1250&lt;BR /&gt;
18018 2 1150 &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data result;&lt;BR /&gt;
 set temp;&lt;BR /&gt;
 if subject ne lag(subject) then count=0;&lt;BR /&gt;
 count+1;&lt;BR /&gt;
 if count le 4;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 18 Feb 2011 04:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Deleting-observations/m-p/9245#M604</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-18T04:53:40Z</dc:date>
    </item>
  </channel>
</rss>

