BookmarkSubscribeRSS Feed
JAR
Obsidian | Level 7 JAR
Obsidian | Level 7
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
2 REPLIES 2
Ksharp
Super User
[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
JAR
Obsidian | Level 7 JAR
Obsidian | Level 7
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1215 views
  • 0 likes
  • 2 in conversation