<?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: Hash object in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250781#M56621</link>
    <description>&lt;P&gt;The following perhaps can work:&lt;/P&gt;
&lt;P&gt;*step 1: calculate the total fee of each auditor in the market;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table sum1 as&lt;BR /&gt;select *,sum(audit_fees) as fee_sum&lt;BR /&gt;&amp;nbsp; from cluster.forum&lt;BR /&gt;&amp;nbsp;&amp;nbsp; group by auditor_fkey, fyear,sic2,cbsa;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;*step 2: calculate the total fees charged in the market;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table sum2 as&lt;BR /&gt;select *,sum(audit_fees) as market_fee&lt;BR /&gt;&amp;nbsp; from sum1&lt;BR /&gt;&amp;nbsp;&amp;nbsp; group by fyear,sic2,cbsa;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;*step 3: calculate the market share of each auditr in the market;&lt;BR /&gt;&lt;BR /&gt;data sum3;&lt;BR /&gt;set sum2;&lt;BR /&gt;fee_shr = fee_sum/market_fee;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;*step 4: calculate the absolute market share difference between current auditor &amp;amp; closest competitors in the market &lt;BR /&gt;(market size is depend on CBSA, SIC2 and fyear);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data cluster.dist (drop=_:);&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;set sum3( rename=(zip1=_zip1) obs=1);&lt;BR /&gt;dcl hash h(dataset: 'sum3 (rename=(zip1=_zip1 fee_shr = _fee_shr))', multidata&amp;amp;colon; 'yes');&lt;BR /&gt;h.definekey('fyear','sic2', 'cbsa');&lt;BR /&gt;h.definedata(all: 'YES');&lt;BR /&gt;h.definedone();&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;set sum3;&lt;BR /&gt;_ct=0;&lt;BR /&gt;_rc=h.find();&lt;BR /&gt;do while (_rc=0);&lt;BR /&gt;distance = zipcitydistance(_zip1,zip1);&lt;BR /&gt;shr_diff = abs(sum(fee_shr, - _fee_shr)); &lt;BR /&gt;if zipcitydistance(_zip1,zip1) =min(zipcitydistance(_zip1,zip1)) &lt;BR /&gt;and abs(sum(fee_shr, - _fee_shr)) = min (abs(sum(fee_shr, - _fee_shr)))&lt;BR /&gt;then _ct1+1;&lt;BR /&gt;h.has_next(result: _r);&lt;BR /&gt;if _r ne 0 then _rc=h.find_next();&lt;BR /&gt;else leave;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Feb 2016 08:52:01 GMT</pubDate>
    <dc:creator>mspak</dc:creator>
    <dc:date>2016-02-18T08:52:01Z</dc:date>
    <item>
      <title>Hash object</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250051#M56568</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Dear all,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The following SQL program is to calculate the market share difference between an&amp;nbsp;audit firmwith its closest (in terms of distance) competitor in the audit market. The step 4 below - to find the closest audit firm is too time consuming. I would be much appreciate if anyone can find a solution that can save the processing time, possibly in hash object.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*step 1: calculate the total fee of each auditor in the market;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table sum1 as&lt;BR /&gt;select *,sum(audit_fees) as fee_sum&lt;BR /&gt; from cluster.forum&lt;BR /&gt; group by auditor_fkey, fyear,sic2,cbsa;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;*step 2: calculate the total fees charged in the market;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table sum2 as&lt;BR /&gt;select *,sum(audit_fees) as market_fee&lt;BR /&gt; from sum1&lt;BR /&gt; group by fyear,sic2,cbsa;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;*step 3: calculate the market share of each auditr in the market;&lt;/P&gt;
&lt;P&gt;data sum3;&lt;BR /&gt;set sum2;&lt;BR /&gt;fee_shr = fee_sum/market_fee;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;*step 4: calculate the closest competitors in the market &lt;BR /&gt;(market size is depend on CBSA, SIC2 and fyear);&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table cluster.dist as&lt;BR /&gt;select a.*, min(zipcitydistance(a.zip1,b.zip1)) as min_dist&lt;BR /&gt;from sum3 a , sum3 b&lt;BR /&gt;group by a.fyear, a.sic2, a.cbsa&lt;BR /&gt;having not missing(calculated min_dist);&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;*step5: only output the data with closest competitors in the market;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regadrs,&lt;/P&gt;
&lt;P&gt;MSPAK&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 10:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250051#M56568</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2016-02-15T10:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Hash object</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250057#M56569</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no test data given (datastep please) so not able to code. &amp;nbsp;However if you find SQL is taking to long, consider converting it to a datastep. &amp;nbsp;None of those proc sql steps are doing anything particularly difficult to in datastep, or in fact using the procedures supplied by Base SAS. &amp;nbsp;For instance, your first two steps could be done in one datastep. &amp;nbsp;The last step, it seems to be working on all records from sum3 * sum3, which could lead to lots of data merging together. &amp;nbsp;Bit difficult to say without some test data to run it on.&lt;/P&gt;
&lt;PRE&gt;data sum3;
  set cluster.forum;
  retain fee_sum market_fee fee_shr;
  by auditor_fkey fyear sic2 cbsa;
  /* Note I am assuming auditor_fkey is the main group here */
  if first.auditor_fkey then fee_sum=audit_fees;
  else fee_sum=sum(fee_sum,audit_fees);
  if first.fyear then fee_shr=audit_fees;
  else fee_shr=sum(fee_shr,audit_fees);
  if last.auditor_fkey then do;
    fee_shr=fee_sum/market_fee;
    output;
  end;
run;
  &lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Feb 2016 10:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250057#M56569</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-15T10:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Hash object</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250058#M56570</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Thank you for your mail. I attached the dataset in zip file in my previous post. My first 3 steps can be done without any problem, but not for the step 4. I understand the hash object can help much, but I find the codes in hash objects are difficult. I am seeking for any helps in coding, particularly in hash object or any programs that can reduce processing time.&lt;BR /&gt;&lt;BR /&gt;Thank you.</description>
      <pubDate>Mon, 15 Feb 2016 10:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250058#M56570</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2016-02-15T10:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Hash object</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250059#M56571</link>
      <description>&lt;P&gt;Sorry, am not downloading attachments. &amp;nbsp;Code converted for the first 3 steps is given, same can be applied to the last one, with your data. &amp;nbsp;I would look specifically at this part:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;from sum3 a , sum3 b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;group by a.fyear, a.sic2, a.cbsa&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;having not missing(calculated min_dist);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is creating a table of all rows from sum3 * all rows from sum3. &amp;nbsp;This creates lots of data, and I don't know why it is programmed that way. &amp;nbsp;Break it out into separate steps if you have to, i.e. create a dataset with the records you want to see, (just do the merge). &amp;nbsp;How many records is that? &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 10:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250059#M56571</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-15T10:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hash object</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250062#M56572</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your code. I can process the data using SQL for the first 3 steps, but not for the step 4.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data sum3 should includes the market share for each audit firm in the market. The audit market boundary is defined by sic2 (industrry codes), fyear (years) and CBSA. CBSA is&amp;nbsp;&lt;EM&gt;Core Based Statistical Area (refer&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Core-based_statistical_area).&amp;nbsp;" target="_blank"&gt;https://en.wikipedia.org/wiki/Core-based_statistical_area).&amp;nbsp;&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to identify the market share difference between an audit firm with its closest competitor in the market. Zip codes (zip1) is given the dataset. zipcitydistance function should be used (&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003113156.htm)" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003113156.htm)&lt;/A&gt; to be used for calculating the distance between 2 zipcodes in USA.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is one to many matching, but I only wish to output the obs with closest competitor. The output should contain the unique&amp;nbsp;auditor_fkey (auditor identification code) with their closest competitor in the market.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;mspak&lt;/P&gt;
&lt;H1&gt;&amp;nbsp;&lt;/H1&gt;</description>
      <pubDate>Mon, 15 Feb 2016 10:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250062#M56572</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2016-02-15T10:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Hash object</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250112#M56573</link>
      <description>&lt;P&gt;When I perform the SQL on step 4, the following message recorded:&lt;/P&gt;
&lt;P&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that&lt;BR /&gt; can not be optimized.&lt;/P&gt;
&lt;P&gt;NOTE: The query requires remerging summary statistics back with the original data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am asking for helps in solving the problems of huge data as a result of Cartesian joins.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;MSPAK&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 15:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250112#M56573</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2016-02-15T15:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Hash object</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250781#M56621</link>
      <description>&lt;P&gt;The following perhaps can work:&lt;/P&gt;
&lt;P&gt;*step 1: calculate the total fee of each auditor in the market;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table sum1 as&lt;BR /&gt;select *,sum(audit_fees) as fee_sum&lt;BR /&gt;&amp;nbsp; from cluster.forum&lt;BR /&gt;&amp;nbsp;&amp;nbsp; group by auditor_fkey, fyear,sic2,cbsa;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;*step 2: calculate the total fees charged in the market;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table sum2 as&lt;BR /&gt;select *,sum(audit_fees) as market_fee&lt;BR /&gt;&amp;nbsp; from sum1&lt;BR /&gt;&amp;nbsp;&amp;nbsp; group by fyear,sic2,cbsa;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;*step 3: calculate the market share of each auditr in the market;&lt;BR /&gt;&lt;BR /&gt;data sum3;&lt;BR /&gt;set sum2;&lt;BR /&gt;fee_shr = fee_sum/market_fee;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;*step 4: calculate the absolute market share difference between current auditor &amp;amp; closest competitors in the market &lt;BR /&gt;(market size is depend on CBSA, SIC2 and fyear);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data cluster.dist (drop=_:);&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;set sum3( rename=(zip1=_zip1) obs=1);&lt;BR /&gt;dcl hash h(dataset: 'sum3 (rename=(zip1=_zip1 fee_shr = _fee_shr))', multidata&amp;amp;colon; 'yes');&lt;BR /&gt;h.definekey('fyear','sic2', 'cbsa');&lt;BR /&gt;h.definedata(all: 'YES');&lt;BR /&gt;h.definedone();&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;set sum3;&lt;BR /&gt;_ct=0;&lt;BR /&gt;_rc=h.find();&lt;BR /&gt;do while (_rc=0);&lt;BR /&gt;distance = zipcitydistance(_zip1,zip1);&lt;BR /&gt;shr_diff = abs(sum(fee_shr, - _fee_shr)); &lt;BR /&gt;if zipcitydistance(_zip1,zip1) =min(zipcitydistance(_zip1,zip1)) &lt;BR /&gt;and abs(sum(fee_shr, - _fee_shr)) = min (abs(sum(fee_shr, - _fee_shr)))&lt;BR /&gt;then _ct1+1;&lt;BR /&gt;h.has_next(result: _r);&lt;BR /&gt;if _r ne 0 then _rc=h.find_next();&lt;BR /&gt;else leave;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2016 08:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hash-object/m-p/250781#M56621</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2016-02-18T08:52:01Z</dc:date>
    </item>
  </channel>
</rss>

