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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1238 views
  • 0 likes
  • 2 in conversation