DATA Step, Macro, Functions and more

Growth By Product Per Quarter

Reply
Contributor JAR
Contributor
Posts: 45

Growth By Product Per Quarter

HI All,
I have the follwing issue:

Product..Month.......Sales
x.......April.......10
y.......April.......5
x.......May.......12
y.......May.......12
x.......June.......15
y.......June.......14

I would like SAS do the the following:
Product.......Growth
x.......15-10
y.......14-5

In fact, for the data I have, i will be calculating yearly growth. And, the date values are all in date format itself.

Thaning you in advance,
Jijil
Super User
Posts: 9,676

Re: Growth By Product Per Quarter

[pre]
data temp;
infile datalines dlm='.';
input Product $ Month : date9. Sales ;
format month monname.;
datalines;
x.......11Apr2009.......10
y.......12Apr2009.......5
x.......14May2009.......12
y.......15May2009.......12
x.......16Jun2009.......15
y.......17Jun2009.......14
;
run;
proc sort data=temp;
by product month ;
run;
data want;
set temp;
by product month;
length growth $ 10;
retain start;
if first.product then start=sales;
if last.product then do;
growth=catx('-',sales,start);
output;
end;
keep product growth;
run;
[/pre]
Ksharp
Contributor JAR
Contributor
Posts: 45

Re: Growth By Product Per Quarter

Dear Ksharp:
Thanks a lot for the code.
I had instered those dots as this forum does not support tab. Anyway, you code works awesome!

Finally, I wanted the actual numerical value instead of 15-10, which is not difficult.

Thanks a million!

Jijil Ramakrishnan
Ask a Question
Discussion stats
  • 2 replies
  • 148 views
  • 0 likes
  • 2 in conversation