<?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 To count number of firms given country year in panel data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535923#M147212</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;I am dealing with international data. I have four variables as follows. I would like to get the following variables and add the new variables at the end of my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; how many firms in each country.&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; how many firms in each country each year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; the average sale in a given year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;3)&amp;nbsp; the average sale in each year in each country&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to do some coding as belows, but it does not work (no error reported, but in the new dataset, there is 0 obs)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;can anyone help?&amp;nbsp;&lt;/SPAN&gt; Many thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input country $ year firm $ sales;&lt;BR /&gt;cards;&lt;/P&gt;&lt;P&gt;a 2000 a0201 20&lt;BR /&gt;a 2001 a0201 32&lt;BR /&gt;a 2002 a0201 31&lt;BR /&gt;a 2000 a0202 10&lt;BR /&gt;a 2001 a0202&amp;nbsp; 9&lt;BR /&gt;a 2000 a0203&amp;nbsp; 7.3&lt;BR /&gt;a 2001 a0203&amp;nbsp; 4&lt;BR /&gt;a 2002 a0203&amp;nbsp; .&lt;BR /&gt;a 2003 a0203&amp;nbsp; 2.9&lt;BR /&gt;b 2000 a0204&amp;nbsp; 13&lt;BR /&gt;b 2001 a0204&amp;nbsp; 13&lt;BR /&gt;b 2002 a0204&amp;nbsp; 18&lt;BR /&gt;b 2003 a0204&amp;nbsp; 17&lt;BR /&gt;b 2004 a0204 15&lt;BR /&gt;b 2000 a0205 33&lt;BR /&gt;b 2001 a0205&amp;nbsp; 45&lt;BR /&gt;b 2002 a0205&amp;nbsp; 32&lt;BR /&gt;b 2003 a0205 &amp;nbsp; 38&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=have; by country year ;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by country year;&lt;BR /&gt;if first.firm then firm=1;else&lt;BR /&gt;count+1;&lt;BR /&gt;if last.firm and count&amp;gt;1 then output;&lt;BR /&gt;proc print; run;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Feb 2019 17:34:58 GMT</pubDate>
    <dc:creator>Elaine_S</dc:creator>
    <dc:date>2019-02-15T17:34:58Z</dc:date>
    <item>
      <title>To count number of firms given country year in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535923#M147212</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;I am dealing with international data. I have four variables as follows. I would like to get the following variables and add the new variables at the end of my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; how many firms in each country.&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; how many firms in each country each year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; the average sale in a given year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;3)&amp;nbsp; the average sale in each year in each country&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to do some coding as belows, but it does not work (no error reported, but in the new dataset, there is 0 obs)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;can anyone help?&amp;nbsp;&lt;/SPAN&gt; Many thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input country $ year firm $ sales;&lt;BR /&gt;cards;&lt;/P&gt;&lt;P&gt;a 2000 a0201 20&lt;BR /&gt;a 2001 a0201 32&lt;BR /&gt;a 2002 a0201 31&lt;BR /&gt;a 2000 a0202 10&lt;BR /&gt;a 2001 a0202&amp;nbsp; 9&lt;BR /&gt;a 2000 a0203&amp;nbsp; 7.3&lt;BR /&gt;a 2001 a0203&amp;nbsp; 4&lt;BR /&gt;a 2002 a0203&amp;nbsp; .&lt;BR /&gt;a 2003 a0203&amp;nbsp; 2.9&lt;BR /&gt;b 2000 a0204&amp;nbsp; 13&lt;BR /&gt;b 2001 a0204&amp;nbsp; 13&lt;BR /&gt;b 2002 a0204&amp;nbsp; 18&lt;BR /&gt;b 2003 a0204&amp;nbsp; 17&lt;BR /&gt;b 2004 a0204 15&lt;BR /&gt;b 2000 a0205 33&lt;BR /&gt;b 2001 a0205&amp;nbsp; 45&lt;BR /&gt;b 2002 a0205&amp;nbsp; 32&lt;BR /&gt;b 2003 a0205 &amp;nbsp; 38&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=have; by country year ;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by country year;&lt;BR /&gt;if first.firm then firm=1;else&lt;BR /&gt;count+1;&lt;BR /&gt;if last.firm and count&amp;gt;1 then output;&lt;BR /&gt;proc print; run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 17:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535923#M147212</guid>
      <dc:creator>Elaine_S</dc:creator>
      <dc:date>2019-02-15T17:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: To count number of firms given country year in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535927#M147215</link>
      <description>&lt;P&gt;Were you missing the firm in the sort?&lt;/P&gt;
&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input country $ year firm $ sales;
cards;
a 2000 a0201 20
a 2001 a0201 32
a 2002 a0201 31
a 2000 a0202 10
a 2001 a0202  9
a 2000 a0203  7.3
a 2001 a0203  4
a 2002 a0203  .
a 2003 a0203  2.9
b 2000 a0204  13
b 2001 a0204  13
b 2002 a0204  18
b 2003 a0204  17
b 2004 a0204 15
b 2000 a0205 33
b 2001 a0205  45
b 2002 a0205  32
b 2003 a0205   38
;
run;
 
proc sort data=have; by firm country year ;run;
data want;
set have;
by firm country year;
if first.firm then firm=1;else
count+1;
if last.firm and count&amp;gt;1 then output;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Feb 2019 17:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535927#M147215</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-02-15T17:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: To count number of firms given country year in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535928#M147216</link>
      <description>&lt;P&gt;1636&lt;BR /&gt;1637 data want;&lt;BR /&gt;1638 set have;&lt;BR /&gt;1639 by country year;&lt;BR /&gt;&lt;FONT color="#800080"&gt;&lt;STRONG&gt;1640&lt;/STRONG&gt;&lt;/FONT&gt; if &lt;FONT color="#800080"&gt;&lt;STRONG&gt;first.firm&lt;/STRONG&gt;&lt;/FONT&gt; then firm=1;else&lt;BR /&gt;1641 count+1;&lt;BR /&gt;1642 if last.firm and count&amp;gt;1 then output;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;NOTE: Numeric values have been converted to character&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;values at the places given by: (Line):(Column).&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1640:25&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;NOTE: Variable first.firm is uninitialized.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;NOTE: Variable last.firm is uninitialized.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;They are not in red, but they are errors in your logic.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260700"&gt;@Elaine_S&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;I am dealing with international data. I have four variables as follows. I would like to get the following variables and add the new variables at the end of my dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp; how many firms in each country.&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp; how many firms in each country each year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp; the average sale in a given year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3)&amp;nbsp; the average sale in each year in each country&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try to do some coding as belows, but it does not work (no error reported, but in the new dataset, there is 0 obs)&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;can anyone help?&amp;nbsp;&lt;/SPAN&gt; Many thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input country $ year firm $ sales;&lt;BR /&gt;cards;&lt;/P&gt;
&lt;P&gt;a 2000 a0201 20&lt;BR /&gt;a 2001 a0201 32&lt;BR /&gt;a 2002 a0201 31&lt;BR /&gt;a 2000 a0202 10&lt;BR /&gt;a 2001 a0202&amp;nbsp; 9&lt;BR /&gt;a 2000 a0203&amp;nbsp; 7.3&lt;BR /&gt;a 2001 a0203&amp;nbsp; 4&lt;BR /&gt;a 2002 a0203&amp;nbsp; .&lt;BR /&gt;a 2003 a0203&amp;nbsp; 2.9&lt;BR /&gt;b 2000 a0204&amp;nbsp; 13&lt;BR /&gt;b 2001 a0204&amp;nbsp; 13&lt;BR /&gt;b 2002 a0204&amp;nbsp; 18&lt;BR /&gt;b 2003 a0204&amp;nbsp; 17&lt;BR /&gt;b 2004 a0204 15&lt;BR /&gt;b 2000 a0205 33&lt;BR /&gt;b 2001 a0205&amp;nbsp; 45&lt;BR /&gt;b 2002 a0205&amp;nbsp; 32&lt;BR /&gt;b 2003 a0205 &amp;nbsp; 38&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have; by country year ;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by country year;&lt;BR /&gt;if first.firm then firm=1;else&lt;BR /&gt;count+1;&lt;BR /&gt;if last.firm and count&amp;gt;1 then output;&lt;BR /&gt;proc print; run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 17:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535928#M147216</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-15T17:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: To count number of firms given country year in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535931#M147217</link>
      <description>&lt;P&gt;Let's consider question 2, and how you would need to change your code to get counts of number of firms in each country year.&amp;nbsp; Right now, you are starting with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have; by country year ;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by country year;&lt;BR /&gt;if first.firm then firm=1;else&lt;BR /&gt;count+1;&lt;BR /&gt;if last.firm and count&amp;gt;1 then output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With slight changes, you can get the answer to that question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have; by country year ;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by country year;&lt;BR /&gt;if first.&lt;FONT color="#FF0000"&gt;year&lt;/FONT&gt; then &lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt;=1;else&lt;BR /&gt;count+1;&lt;BR /&gt;if last.firm;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 17:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535931#M147217</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-15T17:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: To count number of firms given country year in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535932#M147218</link>
      <description>&lt;P&gt;if this by any chance not a datastep assignment and is allowed to be done using stat procedures, will make yours life easy and convenient.&lt;/P&gt;
&lt;P&gt;Of course you would have to merge the results though&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 17:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-count-number-of-firms-given-country-year-in-panel-data/m-p/535932#M147218</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-15T17:48:00Z</dc:date>
    </item>
  </channel>
</rss>

