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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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