<?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 Number of years since the first observation was found in a geographical area in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101129#M28385</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset with the following variables:&lt;/P&gt;&lt;P&gt;gvkey = firm identification code&lt;/P&gt;&lt;P&gt;fyear = financial year (since year 1950)&lt;/P&gt;&lt;P&gt;sic3 = industry classification code based on the first 3-digit&lt;/P&gt;&lt;P&gt;zipcode = US zipcode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wish to calculate the following variable:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Cluster age&lt;/STRONG&gt;, measured as the number of years since the first firm in a given industry (sic3) was founded in the cluster, where&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cluster, is measured as 50 miles radius from the firm (gvkey) (note: 50 miles radius can be calculated by using the zipcode of the firm), for a given financial year (fyear) in a particular industry (sic3).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to calculate cluster age, I must first to know the year that the first firm (in the same industry - SIC3) was found within 50 miles radius from the firm (gvkey), which is also in the same industry as the firm (gvkey). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mathematical formula to calculate &lt;STRONG&gt;cluster age&lt;/STRONG&gt; = fyear - firstyear + 1, where firstyear = the year that the first firm (in the same industry - SIC3) was found within 50 miles radius from the firm (gvkey).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have no idea on how to calculate this variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope to get any suggested SAS code which can help me to calculate the cluster age efficiently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;mspak&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Feb 2013 12:47:59 GMT</pubDate>
    <dc:creator>mspak</dc:creator>
    <dc:date>2013-02-07T12:47:59Z</dc:date>
    <item>
      <title>Number of years since the first observation was found in a geographical area</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101129#M28385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset with the following variables:&lt;/P&gt;&lt;P&gt;gvkey = firm identification code&lt;/P&gt;&lt;P&gt;fyear = financial year (since year 1950)&lt;/P&gt;&lt;P&gt;sic3 = industry classification code based on the first 3-digit&lt;/P&gt;&lt;P&gt;zipcode = US zipcode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wish to calculate the following variable:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Cluster age&lt;/STRONG&gt;, measured as the number of years since the first firm in a given industry (sic3) was founded in the cluster, where&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cluster, is measured as 50 miles radius from the firm (gvkey) (note: 50 miles radius can be calculated by using the zipcode of the firm), for a given financial year (fyear) in a particular industry (sic3).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to calculate cluster age, I must first to know the year that the first firm (in the same industry - SIC3) was found within 50 miles radius from the firm (gvkey), which is also in the same industry as the firm (gvkey). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mathematical formula to calculate &lt;STRONG&gt;cluster age&lt;/STRONG&gt; = fyear - firstyear + 1, where firstyear = the year that the first firm (in the same industry - SIC3) was found within 50 miles radius from the firm (gvkey).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have no idea on how to calculate this variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope to get any suggested SAS code which can help me to calculate the cluster age efficiently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;mspak&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 12:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101129#M28385</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2013-02-07T12:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Number of years since the first observation was found in a geographical area</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101130#M28386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might have a better source for lat/long than sashelp...but this might get you started: (yeah for spherical geometry)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; %let pi180=0.0174532925199433;&lt;/P&gt;&lt;P&gt;proc sort in=tmp.testdata out=work.testdata;&lt;/P&gt;&lt;P&gt;by gvkey fyear;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort in=tmp.testdata out=work.testdata_srt nodupkey;&lt;/P&gt;&lt;P&gt;by gvkey;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table work.testdata_geo as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.gvkey&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t1.fyear&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t1.sic3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t1.zipcode&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t2.y as latitude_y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t2.x as longitude_x&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; work.testdata_srt t1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left outer join sashelp.zipcode t2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on input(t1.zipcode,5.)=t2.zip;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;alter table work.testdata_geo add constraint pk_tg primary key (gvkey);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table work.clusters as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.sic3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t1.zipcode&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,min(t2.fyear) as Cluster_Start&lt;/P&gt;&lt;P&gt;from &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; work.testdata_geo t1, work.testdata_geo t2&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.sic3=t2.sic3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and (7921.6623*arsin(sqrt((sin((&amp;amp;pi180*t2.latitude_y - &amp;amp;pi180*t1.latitude_y)/2))**2 +&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cos(&amp;amp;pi180*t1.latitude_y)*cos(&amp;amp;pi180*t2.latitude_y)*(sin((&amp;amp;pi180*t2.longitude_x - &amp;amp;pi180*t1.longitude_x)/2))**2))) &amp;lt; 50&lt;/P&gt;&lt;P&gt;group by t1.sic3, t1.zipcode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t2.cluster_start&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t1.fyear - t2.cluster_start + 1 as Cluster_Age&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp.testdata t1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left outer join work.clusters t2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on t1.sic3=t2.sic3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and t1.zipcode=t2.zipcode;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 13:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101130#M28386</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-02-07T13:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Number of years since the first observation was found in a geographical area</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101131#M28387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks DBailey for the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I always used zipcitydistance function in SAS to calculate the geographical distance. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can the following&lt;/P&gt;&lt;P&gt;(7921.6623*arsin(sqrt((sin((&amp;amp;pi180*t2.latitude_y - &amp;amp;pi180*t1.latitude_y)/2))**2 +&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cos(&amp;amp;pi180*t1.latitude_y)*cos(&amp;amp;pi180*t2.latitude_y)*(sin((&amp;amp;pi180*t2.longitude_x - &amp;amp;pi180*t1.longitude_x)/2))**2))) &amp;lt; 50&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;replaced with&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&amp;lt;zipcitydistance&amp;lt;=50?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;mspak&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2013 02:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101131#M28387</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2013-02-08T02:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Number of years since the first observation was found in a geographical area</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101132#M28388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;well...knowing that sas had a function to do that would have saved me countless hours of scanning my old math books several years ago when I needed the same calculation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yes it works fine.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2013 13:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-years-since-the-first-observation-was-found-in-a/m-p/101132#M28388</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-02-08T13:29:12Z</dc:date>
    </item>
  </channel>
</rss>

