<?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: how to subset observations based on id if they exist for all years.... NEED HELP in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102339#M854</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hey thanks Lea&amp;nbsp; works perfect&lt;/P&gt;&lt;P&gt;Ahmad &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Jul 2012 02:17:50 GMT</pubDate>
    <dc:creator>Ahmad</dc:creator>
    <dc:date>2012-07-09T02:17:50Z</dc:date>
    <item>
      <title>how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102334#M849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi i have a data set with the following variables stockname price date year&lt;/P&gt;&lt;P&gt;i have data for 7 years for 100+ stocks&lt;/P&gt;&lt;P&gt;i want to subset my data set and keep only those stocks which have been traded in all years,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;input stockname price date year;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;abc 26&amp;nbsp; 20071205 2007&lt;/P&gt;&lt;P&gt;abc 35 20071206 2007&lt;/P&gt;&lt;P&gt;abc 75 20080123 2008&lt;/P&gt;&lt;P&gt;abc 45 20080612 2008&lt;/P&gt;&lt;P&gt;abc 55 20090612 2009&lt;/P&gt;&lt;P&gt;xyz 26&amp;nbsp; 20071205 2007&lt;/P&gt;&lt;P&gt;xyz 35 20071206 2007&lt;/P&gt;&lt;P&gt; xyz 75 20080123 2008&lt;/P&gt;&lt;P&gt;xyz&amp;nbsp; 45 20080612 2008&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Now in this example stock abc is traded for all three years but xyz is not , i want to subset data to exclude all stocks that are not traded foro the whole time period&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 00:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102334#M849</guid>
      <dc:creator>Ahmad</dc:creator>
      <dc:date>2012-07-09T00:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102335#M850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you know that the number of years is constant (7), I would use first. and last. logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data=dataset;&lt;/P&gt;&lt;P&gt;by stockname;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data limit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by stockname;&lt;/P&gt;&lt;P&gt;if first.stockname then counter = 0;&lt;/P&gt;&lt;P&gt;counter + 1;&lt;/P&gt;&lt;P&gt;if last.stockname;&lt;/P&gt;&lt;P&gt;if counter lt 7 then delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will give you only the final year for the stocks you want, and you can go back and pick up the other data if you need it.&lt;/P&gt;&lt;P&gt;Does this work?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lea&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 01:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102335#M850</guid>
      <dc:creator>Lea</dc:creator>
      <dc:date>2012-07-09T01:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102336#M851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks for the reply, but you mean to say i will have to pick the other data manually, (e.g if i know the stcoks which have data for 7 years, how would i subset my data for all only those stocks??)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 01:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102336#M851</guid>
      <dc:creator>Ahmad</dc:creator>
      <dc:date>2012-07-09T01:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102337#M852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;because the number of stocks is several hundred, close to 500, and the frequency is daily&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 01:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102337#M852</guid>
      <dc:creator>Ahmad</dc:creator>
      <dc:date>2012-07-09T01:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102338#M853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I'm understanding your problem correctly, you can use two steps.&amp;nbsp; First, de-dupe your data by stock and year, and then run the logic above to grab only those stocks traded in all 7 years.&amp;nbsp; Second, you would merge that list of stocks back with your other data (that picks up price and date) to get the final dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data final;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge limit (in=in1 keep=stockname) dataset;&lt;/P&gt;&lt;P&gt;by stockname;&lt;/P&gt;&lt;P&gt;if in1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 02:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102338#M853</guid>
      <dc:creator>Lea</dc:creator>
      <dc:date>2012-07-09T02:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102339#M854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hey thanks Lea&amp;nbsp; works perfect&lt;/P&gt;&lt;P&gt;Ahmad &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 02:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102339#M854</guid>
      <dc:creator>Ahmad</dc:creator>
      <dc:date>2012-07-09T02:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102340#M855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or SQL. If you like it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input stockname $ price date year;
cards;
abc 26&amp;nbsp; 20071205 2007
abc 35 20071206 2007
abc 75 20080123 2008
abc 45 20080612 2008
abc 55 20090612 2009
xyz 26&amp;nbsp; 20071205 2007
xyz 35 20071206 2007
xyz 75 20080123 2008
xyz&amp;nbsp; 45 20080612 2008
;
run;
proc sql ;
select count(distinct year) into : n from have;
create table want as
 select * from have 
&amp;nbsp; where stockname in (
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select stockname from (select stockname,year,count(*) as _count from have group by stockname,year)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by stockname
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having count(year) eq &amp;amp;n);
quit; 

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 03:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102340#M855</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-07-09T03:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102341#M856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or maybe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #0000ff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;create&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;table&lt;SPAN style="color: #000000;"&gt; want &lt;/SPAN&gt;as&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #0000ff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;select&lt;SPAN style="color: #000000;"&gt; * &lt;/SPAN&gt;from&lt;SPAN style="color: #000000;"&gt; have&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;by&lt;/SPAN&gt; stockname&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; having count(&lt;SPAN style="color: #0000ff;"&gt;distinct&lt;/SPAN&gt; year)&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EQ (&lt;SPAN style="color: #0000ff;"&gt;select&lt;/SPAN&gt; range(year)+&lt;SPAN style="color: #008080;"&gt;1&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;from&lt;/SPAN&gt; have)&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; &lt;SPAN style="color: #0000ff;"&gt;order&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;by&lt;/SPAN&gt; stockname, date ;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jul 2012 13:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102341#M856</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2012-07-09T13:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102342#M857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Howles.&lt;/P&gt;&lt;P&gt;Which remind me the skill I have forgotten. I am old i think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;proc sql ;
create table want as
 select * from have 
&amp;nbsp;&amp;nbsp;&amp;nbsp; group by stockname
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having count(distinct year) eq (select count(distinct year) from have);
quit; 

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jul 2012 09:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102342#M857</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-07-10T09:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102343#M858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would still use RANGE to determine the correct number of years. Consider this test data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&lt;SPAN style="color: #000080;"&gt;data&lt;/SPAN&gt; have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&lt;SPAN style="color: #0000ff;"&gt;input&lt;/SPAN&gt; stockname $ price date year;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #0000ff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;cards&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;abc 35 20071206 2007&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;abc 55 20090612 2009&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jul 2012 13:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102343#M858</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2012-07-10T13:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset observations based on id if they exist for all years.... NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102344#M859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ksharp can you please explain your code a bit, as it only gives one value per stock per year, but what i want is to get daily data for stocks which have data for all seven years. Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Nov 2012 22:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/how-to-subset-observations-based-on-id-if-they-exist-for-all/m-p/102344#M859</guid>
      <dc:creator>Ahmad</dc:creator>
      <dc:date>2012-11-25T22:42:35Z</dc:date>
    </item>
  </channel>
</rss>

