<?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: Selecting observations that appear in all years in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525734#M32845</link>
    <description>&lt;P&gt;Maybe something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table work.want as
   select *
      from work.have
         group by Id
            having count(*) = 2017-1999+1
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 09 Jan 2019 15:14:09 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2019-01-09T15:14:09Z</dc:date>
    <item>
      <title>Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525727#M32842</link>
      <description>&lt;P&gt;Good Morning did some google searching and searching through SAS Communities and did not see a solution for what I would like to do, I'm sure its out there just can't find it.&amp;nbsp; Continuing my search but thought I'd post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with observations from 1999 - 2017, trying to figure out a simple way to select observations that appear in each and every year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cannot think of a way to translate&amp;nbsp;a sub-setting statement ......id must appear in every year&amp;nbsp;&amp;nbsp;OR Id cannot be missing for any year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Observations are unique by&amp;nbsp;id and year but may not repeat for each year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry should ay that I know I could subset the file into 1 data set for every year and then rejoin based on year 1999 using id, but there must be a better way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 15:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525727#M32842</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-01-09T15:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525728#M32843</link>
      <description>&lt;P&gt;There are several ways to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you post some example data for us to provide a usable code answer?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 14:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525728#M32843</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-09T14:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525732#M32844</link>
      <description>Id Year Name Score&lt;BR /&gt;1 1999 A 85&lt;BR /&gt;1 2000 A 85&lt;BR /&gt;1 2001 A 87&lt;BR /&gt;1 2002 A 85&lt;BR /&gt;1 2003 A 85&lt;BR /&gt;1 2004 A 85&lt;BR /&gt;1 2005 A 85&lt;BR /&gt;1 2006 A 85&lt;BR /&gt;1 2007 A 85&lt;BR /&gt;1 2008 A 90&lt;BR /&gt;1 2009 A 85&lt;BR /&gt;1 2010 A 85&lt;BR /&gt;1 2011 A 82&lt;BR /&gt;1 2012 A 85&lt;BR /&gt;1 2013 A 85&lt;BR /&gt;1 2014 A 85&lt;BR /&gt;1 2015 A 85&lt;BR /&gt;1 2016 A 85&lt;BR /&gt;1 2017 A 85&lt;BR /&gt;2 1999 B 85&lt;BR /&gt;2 2000 B 85&lt;BR /&gt;2 2002 B 85&lt;BR /&gt;2 2003 B 85&lt;BR /&gt;2 2004 B 85&lt;BR /&gt;2 2005 B 85&lt;BR /&gt;2 2006 B 85&lt;BR /&gt;2 2007 B 85&lt;BR /&gt;2 2008 B 90&lt;BR /&gt;2 2009 B 85&lt;BR /&gt;2 2010 B 85&lt;BR /&gt;2 2011 B 82&lt;BR /&gt;2 2012 B 85&lt;BR /&gt;2 2013 B 85&lt;BR /&gt;2 2014 B 85&lt;BR /&gt;2 2015 B 85&lt;BR /&gt;2 2016 B 85&lt;BR /&gt;2 2017 B 85&lt;BR /&gt;&lt;BR /&gt;So we do not Id 2 because it had no score in 2001, if there is no score and no observation for a given year want to drop the observation&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Jan 2019 15:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525732#M32844</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-01-09T15:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525734#M32845</link>
      <description>&lt;P&gt;Maybe something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table work.want as
   select *
      from work.have
         group by Id
            having count(*) = 2017-1999+1
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jan 2019 15:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525734#M32845</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-01-09T15:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525737#M32846</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id Year Name $ Score;
cards;
1 1999 A 85
1 2000 A 85
1 2001 A 87
1 2002 A 85
1 2003 A 85
1 2004 A 85
1 2005 A 85
1 2006 A 85
1 2007 A 85
1 2008 A 90
1 2009 A 85
1 2010 A 85
1 2011 A 82
1 2012 A 85
1 2013 A 85
1 2014 A 85
1 2015 A 85
1 2016 A 85
1 2017 A 85
2 1999 B 85
2 2000 B 85
2 2002 B 85
2 2003 B 85
2 2004 B 85
2 2005 B 85
2 2006 B 85
2 2007 B 85
2 2008 B 90
2 2009 B 85
2 2010 B 85
2 2011 B 82
2 2012 B 85
2 2013 B 85
2 2014 B 85
2 2015 B 85
2 2016 B 85
2 2017 B 85
;

proc sql noprint;
select max(c) into :m 
from
(select count(id) as c from have group by id );
create table want as
select *
from have
group by id
having count(id)=&amp;amp;m;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jan 2019 15:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525737#M32846</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-09T15:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525738#M32847</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
    class id;
    var year;
    output out=yearstats min=minyear max=maxyear n=nyear;
run;
data want;
    if _n_=1 then set yearstats(where=(_type_=0) keep=minyear maxyear _type_);
    merge have yearstats(where=(_type_=1) keep=nyear _type_);
    by id;
    if nyear&amp;lt;(maxyear-minyear+1) then delete;
    drop _type_;
run;
    
    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hashtag: #PROCSUMMARYRULEZ&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2019 19:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525738#M32847</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-10T19:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525740#M32848</link>
      <description>&lt;P&gt;Thank you everyone as I looked at the solutions I think they would all work but this one seemed the most simplistic, and easiest to validate.&amp;nbsp; Did not think o using a having statement this way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 15:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525740#M32848</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-01-09T15:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525743#M32849</link>
      <description>&lt;P&gt;Just remember to change the solution from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;if newer data contains 2018 or later records, or if at some point data from 1999 is removed from the analysis, &lt;EM&gt;etc&lt;/EM&gt;. Or use a more general approach that figures out the max and min years.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 15:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525743#M32849</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-09T15:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations that appear in all years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525751#M32850</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id $ Year Name $ Score;
datalines;
1 1999 A 85
1 2000 A 85
1 2001 A 87
1 2002 A 85
1 2003 A 85
1 2004 A 85
1 2005 A 85
1 2006 A 85
1 2007 A 85
1 2008 A 90
1 2009 A 85
1 2010 A 85
1 2011 A 82
1 2012 A 85
1 2013 A 85
1 2014 A 85
1 2015 A 85
1 2016 A 85
1 2017 A 85
2 1999 B 85
2 2000 B 85
2 2002 B 85
2 2003 B 85
2 2004 B 85
2 2005 B 85
2 2006 B 85
2 2007 B 85
2 2008 B 90
2 2009 B 85
2 2010 B 85
2 2011 B 82
2 2012 B 85
2 2013 B 85
2 2014 B 85
2 2015 B 85
2 2016 B 85
2 2017 B 85
;

data _null_;
   if _N_ = 1 then do;
      declare hash h(dataset:'have');
      h.defineKey('Id', 'Year');
      h.defineDone();    

      declare hash out(dataset:'have', multidata:'Y');
      out.defineKey('Id');
      out.definedata(all:'Y');
      out.defineDone();
   end;

   set have end=eof;
   by ID;

   if h.check()=0 then c+1;

   if last.id then do;
      if c ne (2017-1999+1) then out.remove(key:Id);
      c=0;
   end;

   if eof then out.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jan 2019 15:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-that-appear-in-all-years/m-p/525751#M32850</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-09T15:58:07Z</dc:date>
    </item>
  </channel>
</rss>

