<?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: Counting number of deals prior to the focal year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-deals-prior-to-the-focal-year/m-p/532290#M145849</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215463"&gt;@jimmychoi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data work.deals;
attrib TargetFirm length = $50
		Acquirer length = $50
		Year format = best4.
		Deal_Type length = $50
		;
infile datalines dlm = "," truncover;
input Year Deal_Type $ TargetFirm $ Acquirer $;
datalines;
2019,M&amp;amp;A,Foxcon,Apple
2018,Partnership,Apple,Samsung
2016,Partnership,Apple,Huawei
2015,Partnership,Apple,LG
2015,Partnership,Foxcon,Apple
2015,M&amp;amp;A,BOSCH,Apple
2015,M&amp;amp;A,Apple,Blackberry
2013,Partnership,Foxcon,Apple
;
run;

data want;
if _n_=1 then do;
if 0 then set deals(rename=(year=_year deal_type=_deal_type));
  dcl hash H (dataset:'deals(rename=(year=_year deal_type=_deal_type))',multidata:'y') ;
   h.definekey  ("Acquirer") ;
   h.definedata ("_year","_deal_type") ;
   h.definedone () ;
 end;
 set deals;
 if deal_type='M&amp;amp;A' then do;
 Acq_NumOfCoop=0;
 AcqTar_NumOfCoop=0;
 do rc=h.find() by 0 while(rc=0);
if  year-5&amp;lt;=_year&amp;lt;=year-1 then Acq_NumOfCoop=sum(Acq_NumOfCoop,1);
if  year-5&amp;lt;=_year&amp;lt;=year-1 and _deal_type ne 'M&amp;amp;A' then AcqTar_NumOfCoop=sum(AcqTar_NumOfCoop,1);
 rc=h.find_next();
 end;
 end;
 drop _: rc;
 run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I appreciate your well written question this time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; thumbs up !!!&lt;/P&gt;</description>
    <pubDate>Sat, 02 Feb 2019 16:51:03 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-02-02T16:51:03Z</dc:date>
    <item>
      <title>Counting number of deals prior to the focal year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-deals-prior-to-the-focal-year/m-p/532280#M145845</link>
      <description>&lt;P&gt;Hi, this is my dataset&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.deals;
attrib TargetFirm length = $50
		Acquirer length = $50
		Year format = best4.
		Deal_Type length = $50
		;
infile datalines dlm = ",";
input Year Deal_Type $ TargetFirm $ Acquirer $;
datalines;
2019,M&amp;amp;A,Foxcon,Apple
2018,Partnership,Apple,Samsung
2016,Partnership,Apple,Huawei
2015,Partnership,Apple,LG
2015,Partnership,Foxcon,Apple
2015,M&amp;amp;A,BOSCH,Apple
2015,M&amp;amp;A,Apple,Blackberry
2013,Partnership,Foxcon	Apple
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to do two things:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1.&amp;nbsp;Acq_NumOfCoop&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Count the number of deals (including partnership, M&amp;amp;A, and etc) of last 5 years prior to the deal (M&amp;amp;A) year&lt;/P&gt;&lt;P&gt;ex) Let's say there's Apple and there was a M&amp;amp;A with Foxcon in year 2019 (focal year).&lt;/P&gt;&lt;P&gt;Then, the question is, how many deals Apple accomplished, regardless of the subject (company) of the deal,&amp;nbsp; from the year 2014 to 2018?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. AcqTar_NumOfCoop &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Count the number of partnerships (this doesn't count M&amp;amp;A deals) between specific companies, from last 5 years prior to a M&amp;amp;A deal.&lt;/P&gt;&lt;P&gt;ex) If there was a M&amp;amp;A deal between Apple and Foxcon in year 2019, then before this, how many partnership deals were made between those two specific companies, from 2014 to 2018?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected outcome would be like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;year&lt;/TD&gt;&lt;TD&gt;Deal.Type&lt;/TD&gt;&lt;TD&gt;TargetFirm&lt;/TD&gt;&lt;TD&gt;Acquirer&lt;/TD&gt;&lt;TD&gt;Acq_NumOfCoop&lt;/TD&gt;&lt;TD&gt;AcqTar_NumOfCoop&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;M&amp;amp;A&lt;/TD&gt;&lt;TD&gt;Foxcon&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;Partnership&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;Samsung&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;Partnership&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;Huawei&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;TD&gt;Partnership&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;LG&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;TD&gt;Partnership&lt;/TD&gt;&lt;TD&gt;Foxcon&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;TD&gt;M&amp;amp;A&lt;/TD&gt;&lt;TD&gt;BOSCH&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;TD&gt;M&amp;amp;A&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;Blackberry&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2013&lt;/TD&gt;&lt;TD&gt;Partnership&lt;/TD&gt;&lt;TD&gt;Foxcon&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;TD&gt;N/A&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 15:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-deals-prior-to-the-focal-year/m-p/532280#M145845</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-02-02T15:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of deals prior to the focal year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-deals-prior-to-the-focal-year/m-p/532290#M145849</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215463"&gt;@jimmychoi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data work.deals;
attrib TargetFirm length = $50
		Acquirer length = $50
		Year format = best4.
		Deal_Type length = $50
		;
infile datalines dlm = "," truncover;
input Year Deal_Type $ TargetFirm $ Acquirer $;
datalines;
2019,M&amp;amp;A,Foxcon,Apple
2018,Partnership,Apple,Samsung
2016,Partnership,Apple,Huawei
2015,Partnership,Apple,LG
2015,Partnership,Foxcon,Apple
2015,M&amp;amp;A,BOSCH,Apple
2015,M&amp;amp;A,Apple,Blackberry
2013,Partnership,Foxcon,Apple
;
run;

data want;
if _n_=1 then do;
if 0 then set deals(rename=(year=_year deal_type=_deal_type));
  dcl hash H (dataset:'deals(rename=(year=_year deal_type=_deal_type))',multidata:'y') ;
   h.definekey  ("Acquirer") ;
   h.definedata ("_year","_deal_type") ;
   h.definedone () ;
 end;
 set deals;
 if deal_type='M&amp;amp;A' then do;
 Acq_NumOfCoop=0;
 AcqTar_NumOfCoop=0;
 do rc=h.find() by 0 while(rc=0);
if  year-5&amp;lt;=_year&amp;lt;=year-1 then Acq_NumOfCoop=sum(Acq_NumOfCoop,1);
if  year-5&amp;lt;=_year&amp;lt;=year-1 and _deal_type ne 'M&amp;amp;A' then AcqTar_NumOfCoop=sum(AcqTar_NumOfCoop,1);
 rc=h.find_next();
 end;
 end;
 drop _: rc;
 run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I appreciate your well written question this time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; thumbs up !!!&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 16:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-deals-prior-to-the-focal-year/m-p/532290#M145849</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-02T16:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of deals prior to the focal year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-deals-prior-to-the-focal-year/m-p/532297#M145852</link>
      <description>&lt;P&gt;This one is rather Tedious but whatever!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;




data work.deals;
attrib TargetFirm length = $50
		Acquirer length = $50
		Year format = best4.
		Deal_Type length = $50
		;
infile datalines dlm = "," truncover;
input Year Deal_Type $ TargetFirm $ Acquirer $;
datalines;
2019,M&amp;amp;A,Foxcon,Apple
2018,Partnership,Apple,Samsung
2016,Partnership,Apple,Huawei
2015,Partnership,Apple,LG
2015,Partnership,Foxcon,Apple
2015,M&amp;amp;A,BOSCH,Apple
2015,M&amp;amp;A,Apple,Blackberry
2013,Partnership,Foxcon,Apple
;
run;


proc sql;
create table want as
select a.*,ifn(a.deal_type='M&amp;amp;A',sum(a.year-5&amp;lt;=b.year&amp;lt;=a.year-1),.) as Acq_NumOfCoop,ifn(a.deal_type='M&amp;amp;A',sum(a.year-5&amp;lt;=b.year&amp;lt;=a.year-1 and b.deal_type ne 'M&amp;amp;A'),.) as AcqTar_NumOfCoop
from deals a, deals b
where a.Acquirer=b.Acquirer 
group by a.Acquirer,a.year,a.targetfirm,a.deal_type
order a.year desc;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 17:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-deals-prior-to-the-focal-year/m-p/532297#M145852</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-02T17:13:18Z</dc:date>
    </item>
  </channel>
</rss>

