<?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 all groups fitting criteria in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584436#M17875</link>
    <description>&lt;P&gt;I'm just glad you found your answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Aug 2019 06:30:18 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-08-28T06:30:18Z</dc:date>
    <item>
      <title>Selecting all groups fitting criteria</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584332#M17868</link>
      <description>&lt;P&gt;I am a relatively novice SAS user doing finance research.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a large database of historical data for a number of securities each with a unique CUSIP. I want to select all the securities whose initial offering date is after some specified date, and which were still listed as of a certain date. However I want to include all available data from before and after those dates for those securities. I am using the existence of an end of day price for the first date of my range and last date of my range.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for example, I have daily price data for 5 securities. I want all securities which were listed prior to Jan 1, 2010 and were still listed as of Dec 31, 2014. Securities 1, 3 and 4 meet this criteria but security 2 was initially offered on May 15, 2012 and security 5 was only has price data through October 5, 2013, implying that it is now delisted/defunct. I want some way to get the data for just securities 1, 3 and 4, but including all available data prior to Jan 1, 2010 and after Dec 31, 2014 for those securities. Deleting the data for the CUSIPs I don't want would also work just as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried a number of solutions on this forum that were used for similar problems (like &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-group-of-observations-based-on-conditions/td-p/210694" target="_self"&gt;this one)&lt;/A&gt; but none of them have worked.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 19:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584332#M17868</guid>
      <dc:creator>FinRes</dc:creator>
      <dc:date>2019-08-27T19:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all groups fitting criteria</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584333#M17869</link>
      <description>&lt;P&gt;Welcome to the SAS Community &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;Can you provide some example of what your data looks like? Makes it much easier to provide a usable code answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 19:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584333#M17869</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T19:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all groups fitting criteria</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584334#M17870</link>
      <description>&lt;P&gt;Take a look at the data below (I just made something up).. Only Security 1, 2, and 3 fulfill the criteria that you set up. Security 4 and 5 do not. Hope you can use the code &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;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	do Security=1, 2, 3;
		do date='01jul2009'd to '01jul2015'd;
			Price=rand('integer', 100, 1000);
			output;
		end;
	end;

	Security=4;
	do date='01jul2009'd to '05oct2009'd;
		Price=rand('integer', 100, 1000);
		output;
	end;

	Security=5;
	do date='01jul2010'd to '01jul2015'd;
		Price=rand('integer', 100, 1000);
		output;
	end;

	format date date9.;
run;

data want;
	if _N_=1 then do;
		declare hash h1(dataset:"have(where=(date lt '01jan2010'd))");
		h1.definekey("Security");
		h1.definedone();
		declare hash h2(dataset:"have(where=(date gt '31dec2014'd))");
		h2.definekey("Security");
		h2.definedone();	
	end;

	set have;

	if h1.check()=0 &amp;amp; h2.check()=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Aug 2019 19:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584334#M17870</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T19:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all groups fitting criteria</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584336#M17871</link>
      <description>&lt;P&gt;Alternatively, using PROC SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as
	select * from have
	group by Security
	having sum(date lt '01jan2010'd) &amp;amp; sum(date gt '31dec2014'd)
	order by Security, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Aug 2019 19:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584336#M17871</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T19:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all groups fitting criteria</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584395#M17872</link>
      <description>&lt;P&gt;Thanks! This worked perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did not try the other solution since I am a little more familiar with SQL, though I might try the other solution later too.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 01:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584395#M17872</guid>
      <dc:creator>FinRes</dc:creator>
      <dc:date>2019-08-28T01:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all groups fitting criteria</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584436#M17875</link>
      <description>&lt;P&gt;I'm just glad you found your answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 06:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-all-groups-fitting-criteria/m-p/584436#M17875</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-28T06:30:18Z</dc:date>
    </item>
  </channel>
</rss>

