<?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 Counting Occurrences of a Variable and Deleting Records Based on Count in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Occurrences-of-a-Variable-and-Deleting-Records-Based-on/m-p/35614#M8805</link>
    <description>Wow!  What a long subject line!  But I think it actually captures exactly what I am trying to do.  I am a beginner, so please bear with me.&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset where one of the variables is 'SupervisorName'.  What I would like to be able to do is count the number of times that a particular supervisor name occurs and delete all records which contain a supervisor name that doesn't appear more than 4 times in the dataset.  &lt;BR /&gt;
&lt;BR /&gt;
Example  Dataset (this data has already been read into a SAS dataset):&lt;BR /&gt;
&lt;BR /&gt;
Jim  3   4&lt;BR /&gt;
Jim  4  5&lt;BR /&gt;
Jim  6  7&lt;BR /&gt;
Jim  6  8&lt;BR /&gt;
Jim  3  2&lt;BR /&gt;
Suzy  3  1&lt;BR /&gt;
Suzy  2  1&lt;BR /&gt;
&lt;BR /&gt;
Given this data, I want to delete all records which have Suzy as the supervisor since she occurs less than 4 times.  Leaving only observations where Jim is the supervisor.  This is just example data, the dataset I will be performing this on has  hundreds of observations.&lt;BR /&gt;
&lt;BR /&gt;
Thanks you so much for the help!&lt;BR /&gt;
-jeff</description>
    <pubDate>Fri, 22 May 2009 15:09:12 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-05-22T15:09:12Z</dc:date>
    <item>
      <title>Counting Occurrences of a Variable and Deleting Records Based on Count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Occurrences-of-a-Variable-and-Deleting-Records-Based-on/m-p/35614#M8805</link>
      <description>Wow!  What a long subject line!  But I think it actually captures exactly what I am trying to do.  I am a beginner, so please bear with me.&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset where one of the variables is 'SupervisorName'.  What I would like to be able to do is count the number of times that a particular supervisor name occurs and delete all records which contain a supervisor name that doesn't appear more than 4 times in the dataset.  &lt;BR /&gt;
&lt;BR /&gt;
Example  Dataset (this data has already been read into a SAS dataset):&lt;BR /&gt;
&lt;BR /&gt;
Jim  3   4&lt;BR /&gt;
Jim  4  5&lt;BR /&gt;
Jim  6  7&lt;BR /&gt;
Jim  6  8&lt;BR /&gt;
Jim  3  2&lt;BR /&gt;
Suzy  3  1&lt;BR /&gt;
Suzy  2  1&lt;BR /&gt;
&lt;BR /&gt;
Given this data, I want to delete all records which have Suzy as the supervisor since she occurs less than 4 times.  Leaving only observations where Jim is the supervisor.  This is just example data, the dataset I will be performing this on has  hundreds of observations.&lt;BR /&gt;
&lt;BR /&gt;
Thanks you so much for the help!&lt;BR /&gt;
-jeff</description>
      <pubDate>Fri, 22 May 2009 15:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-Occurrences-of-a-Variable-and-Deleting-Records-Based-on/m-p/35614#M8805</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-22T15:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Occurrences of a Variable and Deleting Records Based on Count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Occurrences-of-a-Variable-and-Deleting-Records-Based-on/m-p/35615#M8806</link>
      <description>Here's one way ...&lt;BR /&gt;
&lt;BR /&gt;
data Test;                                                                                                                              &lt;BR /&gt;
input Name $1-4 Number Value;                                                                                                           &lt;BR /&gt;
datalines;                                                                                                                              &lt;BR /&gt;
Jim  3 4                                                                                                                                &lt;BR /&gt;
Jim  4 5                                                                                                                                &lt;BR /&gt;
Jim  6 7                                                                                                                                &lt;BR /&gt;
Jim  6 8                                                                                                                                &lt;BR /&gt;
Jim  3 2                                                                                                                                &lt;BR /&gt;
Suzy 3 1                                                                                                                                &lt;BR /&gt;
Suzy 2 1                                                                                                                                &lt;BR /&gt;
 ;                                                                                                                                      &lt;BR /&gt;
run;                                                                                                                                    &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
proc freq data=Test;                                                                                                                    &lt;BR /&gt;
table Name/out=SuprvCnt;                                                                                                                &lt;BR /&gt;
run;                                                                                                                                    &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
proc sort data=test;                                                                                                                    &lt;BR /&gt;
by name;                                                                                                                                &lt;BR /&gt;
run;                                                                                                                                    &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
data Test2;                                                                                                                             &lt;BR /&gt;
  merge Test (in=a)                                                                                                                     &lt;BR /&gt;
        SuprvCnt (in=b where=(Count &amp;gt;4));                                                                                              &lt;BR /&gt;
  by Name;                                                                                                                              &lt;BR /&gt;
  if b;                                                                                                                                 &lt;BR /&gt;
run;</description>
      <pubDate>Fri, 22 May 2009 15:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-Occurrences-of-a-Variable-and-Deleting-Records-Based-on/m-p/35615#M8806</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2009-05-22T15:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Occurrences of a Variable and Deleting Records Based on Count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-Occurrences-of-a-Variable-and-Deleting-Records-Based-on/m-p/35616#M8807</link>
      <description>This is compact and easy to read. What out for 2-pass sql performance on large volumes.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data t;&lt;BR /&gt;
input name $ a b;&lt;BR /&gt;
cards;&lt;BR /&gt;
Jim 3 4&lt;BR /&gt;
Jim 4 5&lt;BR /&gt;
Jim 6 7&lt;BR /&gt;
Jim 6 8&lt;BR /&gt;
Jim 3 2&lt;BR /&gt;
Suzy 3 1&lt;BR /&gt;
Suzy 2 1&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre][pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table t1(drop=c) as&lt;BR /&gt;
  select *, count(name) as c &lt;BR /&gt;
  from t &lt;BR /&gt;
  group by name &lt;BR /&gt;
  having c &amp;gt;4 ;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 26 May 2009 21:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-Occurrences-of-a-Variable-and-Deleting-Records-Based-on/m-p/35616#M8807</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-05-26T21:33:38Z</dc:date>
    </item>
  </channel>
</rss>

