<?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 from a by group containing a specific set of dates. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609550#M35231</link>
    <description>&lt;P&gt;Basically the Idea to build the algorithm is simple:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PART1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1. Fiiter by subsetting ID's with dates falling in the range 2016:2018&lt;/P&gt;
&lt;P&gt;2. 1 will have some ID's with all 3 or just 1 or 2 in the range . Example ID A may have 2016 10 times and only 2016. ID B may have all three occuring any number of times , ID C with 2017 and 2018 occuring any number of times&lt;/P&gt;
&lt;P&gt;3. Within the subset, we do a "&lt;EM&gt;&lt;STRONG&gt;distinct count&lt;/STRONG&gt;&lt;/EM&gt;," i.e if the distinct count is equal 3 that means that ID must have all three 2016-2018 .&lt;/P&gt;
&lt;P&gt;4. So this makes ID B our our target&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PART2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;5. Read all records from HAVE, the &lt;STRONG&gt;outer&lt;/STRONG&gt; query and subset only those ID's that resulted from &lt;EM&gt;&lt;STRONG&gt;sub query(PART A)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps you grasp the solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Dec 2019 22:04:34 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-12-04T22:04:34Z</dc:date>
    <item>
      <title>Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609533#M35223</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wondering if it is possible to select observations from a by group containing a specific set of dates. Take the following data for example...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; Date&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2018&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on the data above, I want outputs where IDs can be matched to 2016, 2017, AND 2018 (See example output below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; Date&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2018&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. I am using SAS EG version 7.1.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609533#M35223</guid>
      <dc:creator>kb179208</dc:creator>
      <dc:date>2019-12-04T21:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609537#M35224</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID    Date;
cards;
1     2016
1     2017
1     2018
2     2016
2     2017
3     2016
3     2017
3     2018
;

proc sql;
create table want as
select *
from have
where id in (select id from have where date in (2016:2018) group by id having count(distinct date)=3);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609537#M35224</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-04T21:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609539#M35225</link>
      <description>&lt;P&gt;Thank you much!!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609539#M35225</guid>
      <dc:creator>kb179208</dc:creator>
      <dc:date>2019-12-04T21:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609540#M35226</link>
      <description>&lt;P&gt;One additional question... say that I had duplicate values of some dates (e.g., ID:1 has 2 observations where the date is 2016. Is there a way to modify the code such that it works for these instances as well keeping duplicate values?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609540#M35226</guid>
      <dc:creator>kb179208</dc:creator>
      <dc:date>2019-12-04T21:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609542#M35227</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302342"&gt;@kb179208&lt;/a&gt;&amp;nbsp; Assuming what you mean is the following modified sample&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID    Date;
cards;
1     2016
1	  2016
1     2017
1     2017
1     2018
1     2018
2     2016
2     2017
3     2016
3     2017
3     2018
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code doesn't exclude the dups in the final result. Is my understanding correct?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609542#M35227</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-04T21:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609543#M35228</link>
      <description>&lt;P&gt;yes that is correct&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609543#M35228</guid>
      <dc:creator>kb179208</dc:creator>
      <dc:date>2019-12-04T21:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609545#M35229</link>
      <description>&lt;P&gt;It's still the same code. Test and let me know&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609545#M35229</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-04T21:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609547#M35230</link>
      <description>&lt;P&gt;You are right, the code works for the example I provided so I should have been more clear. I have some IDs that may have 3 observations, but each with a date of 2016. I want to exclude these as they do not also contain date values of 2017 and 2018.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609547#M35230</guid>
      <dc:creator>kb179208</dc:creator>
      <dc:date>2019-12-04T21:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609550#M35231</link>
      <description>&lt;P&gt;Basically the Idea to build the algorithm is simple:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PART1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1. Fiiter by subsetting ID's with dates falling in the range 2016:2018&lt;/P&gt;
&lt;P&gt;2. 1 will have some ID's with all 3 or just 1 or 2 in the range . Example ID A may have 2016 10 times and only 2016. ID B may have all three occuring any number of times , ID C with 2017 and 2018 occuring any number of times&lt;/P&gt;
&lt;P&gt;3. Within the subset, we do a "&lt;EM&gt;&lt;STRONG&gt;distinct count&lt;/STRONG&gt;&lt;/EM&gt;," i.e if the distinct count is equal 3 that means that ID must have all three 2016-2018 .&lt;/P&gt;
&lt;P&gt;4. So this makes ID B our our target&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PART2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;5. Read all records from HAVE, the &lt;STRONG&gt;outer&lt;/STRONG&gt; query and subset only those ID's that resulted from &lt;EM&gt;&lt;STRONG&gt;sub query(PART A)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps you grasp the solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 22:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609550#M35231</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-04T22:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from a by group containing a specific set of dates.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609553#M35232</link>
      <description>&lt;P&gt;I think I know what my problem is. I reformatted the DATE (mmddyyy) variable into a different variable DATE2, where it only shows the year. However, since I set DATE2=DATE it is still picking up the values as distinct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you once again for all the help!! I am not the best with SQL queries in sas.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 22:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-observations-from-a-by-group-containing-a-specific-set/m-p/609553#M35232</guid>
      <dc:creator>kb179208</dc:creator>
      <dc:date>2019-12-04T22:15:26Z</dc:date>
    </item>
  </channel>
</rss>

