<?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 the number of specific rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532061#M145753</link>
    <description>Hi, Novinosrin, I will structure my questions from next one. I wasn't good at questioning, making ambiguous requests, sorry &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
    <pubDate>Fri, 01 Feb 2019 15:55:55 GMT</pubDate>
    <dc:creator>jimmychoi</dc:creator>
    <dc:date>2019-02-01T15:55:55Z</dc:date>
    <item>
      <title>Counting the number of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/531958#M145704</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is how my data would look like:&lt;/P&gt;&lt;P&gt;[Company_A]&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [Company_B]&amp;nbsp; &amp;nbsp; &amp;nbsp; [Year]&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[Deal_Type]&lt;/P&gt;&lt;P&gt;P&amp;amp;G&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pepsi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Partnership&lt;/P&gt;&lt;P&gt;Coke&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Pepsi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2007&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Partnership&lt;/P&gt;&lt;P&gt;Pringles&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;P&amp;amp;G&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2007&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Partnership&lt;/P&gt;&lt;P&gt;Pringles&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;P&amp;amp;G&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2008&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&amp;amp;A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are bunch of similar records, and what I would like to do is two things:&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;Make a new column for the table named 'NumOfCoopsCompB' and count the number of deals of company_B in last 5 years (including 'Partnership' and 'M&amp;amp;A') prior to the deal year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;for example, say, for Coke &amp;amp; Pepsi deal in year 2007, NumOfCoop would be marked as '1', since Pepsi had a deal with P&amp;amp;G in year 2006.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Make a new column for the table named 'NumOfCoopsCompACompB' and count the number of deals (this time only including 'Partnership' deals) between company_A and Company_B in last 5 years, prior to the focal deal year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;for example, say Pringles &amp;amp; P&amp;amp;G deal in year 2008, NumOfCoopsCompACompB would be marked as '1', since in year 2006 they had a partnership deal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Everytime I write a question on this board, I feel like I'm dumb, please help people.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 13:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/531958#M145704</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-02-01T13:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532026#M145740</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;P&gt;For a start&lt;/P&gt;
&lt;P&gt;You wrote- "&lt;SPAN&gt;this is how my data &lt;STRONG&gt;&lt;U&gt;would look&lt;/U&gt;&lt;/STRONG&gt; like:"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. Should I assume that is expected output or input?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. If not, where is your input data sample?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please structure&lt;/STRONG&gt; the question in the following way if you can&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;1. Here is my data input sample&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;2. Here is the business(transformation) logic to process&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;3. Here is my expected output for the input sample&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;That's all we need. Thank you&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PS Cleaner the question, it's easier to respond and saves time.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532026#M145740</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-01T15:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532034#M145745</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
attrib Company_A length = $50
		Company_B length = $50
		Year format = best4.
		Deal_Type length = $50
		;
infile datalines dlm = ",";
input Company_A $ Company_B $ Year Deal_Type $;
datalines;
P&amp;amp;G,Pepsi,2006,Partnership
Coke,Pepsi,2007,Partnership
Pringles,P&amp;amp;G,2007,Partnership
Pringles,P&amp;amp;G,2005,Partnership
Pringles,P&amp;amp;G,2008,M&amp;amp;A
;
run;

data work.have;
ID = _N_;
set work.have;
run;

proc sql;
create table work.want as
	select a.*
	,		sum(b.ID is not missing) as NumOfCoop
	,		sum(b.ID is not missing 
				and b.deal_type eq "Partnership"
				and (	( a.company_a = b.company_a and a.company_b = b.company_b )
					or 	( a.company_b = b.company_a and a.company_a = b.company_b ) )
				) as NumOfCoopsCompACompB 


	from work.have as a
	left join work.have as b on a.year ge b.year 
								and a.year - b.year le 5
								and (a.company_b = b.company_b or a.company_b = b.company_a)
	group by a.ID, a.company_a, a.company_b, a.year, a.deal_type
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532034#M145745</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-02-01T15:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532061#M145753</link>
      <description>Hi, Novinosrin, I will structure my questions from next one. I wasn't good at questioning, making ambiguous requests, sorry &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532061#M145753</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-02-01T15:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532062#M145754</link>
      <description>&lt;P&gt;Relax, nobody has ever been more dumb than me. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532062#M145754</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-01T15:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532225#M145824</link>
      <description>Hi Daniel, thanks I have tried your codes but my system ended up saying: ERROR: Sort execution failure.&lt;BR /&gt;&lt;BR /&gt;I have 132 gigs of free space in my local drive and will there be any other way to optimize the code?</description>
      <pubDate>Fri, 01 Feb 2019 22:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532225#M145824</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-02-01T22:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532522#M145928</link>
      <description>&lt;P&gt;Ok. How many observations in the data? Are there any other Variables? How many companies are roughly in the data? Is it already sorted by anything?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 09:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-specific-rows/m-p/532522#M145928</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-02-04T09:23:58Z</dc:date>
    </item>
  </channel>
</rss>

