BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JohnK
Calcite | Level 5

Dear SAS Users,

I have panel sales data as follows for different firms. How can I calculate year-on-year sales growth? I want something like growth=100*dif12(sales)/lag12(sales) but I don't want dif12 to compare values of different firms.

Thanks for any help in advance.

Firmyearmonthsales
120021
120022
120023
120024
120025
120026
120027
120028
120029
1200210
1200211
1200212
120031
120032
120033
100201112
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

ArthurT,

Your code would not be able to work, If there are some missing monthes or duplicated monthes. But yours is a fast solution.

data have;
input Firm     year     month     sales ;
date=mdy(month,1,year);
format date yymmdd.;
cards;
1     2002     1     1
1     2002     2     1
1     2002     3     1
1     2002     4     1
1     2002     5     1
1     2002     6     1
1     2002     7     1
1     2002     8     1
1     2002     9     1
1     2002     10     1
1     2002     11     1
1     2002     12     1
1     2003     1     1
1     2003     2     1
1     2003     3    1
;
run;
proc sql;
 create table want as
  select *,((select sales from have where firm=h.firm and date=intnx('month',h.date,-12)) -
            (select sales from have where firm=h.firm and date=intnx('month',h.date,-13)) ) /
            (select sales from have where firm=h.firm and date=intnx('month',h.date,-12)) as growth
   from have as h;
quit;


Ksharp

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

Does the following do what you want?:

data want;

  set have;

  by firm;

  if first.firm then counter=1;

  else counter+1;

  growth=ifn(counter gt 12,100*dif12(sales)/lag12(sales),.);

run;

Ksharp
Super User

ArthurT,

Your code would not be able to work, If there are some missing monthes or duplicated monthes. But yours is a fast solution.

data have;
input Firm     year     month     sales ;
date=mdy(month,1,year);
format date yymmdd.;
cards;
1     2002     1     1
1     2002     2     1
1     2002     3     1
1     2002     4     1
1     2002     5     1
1     2002     6     1
1     2002     7     1
1     2002     8     1
1     2002     9     1
1     2002     10     1
1     2002     11     1
1     2002     12     1
1     2003     1     1
1     2003     2     1
1     2003     3    1
;
run;
proc sql;
 create table want as
  select *,((select sales from have where firm=h.firm and date=intnx('month',h.date,-12)) -
            (select sales from have where firm=h.firm and date=intnx('month',h.date,-13)) ) /
            (select sales from have where firm=h.firm and date=intnx('month',h.date,-12)) as growth
   from have as h;
quit;


Ksharp

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 4140 views
  • 3 likes
  • 3 in conversation