BookmarkSubscribeRSS Feed
aarony
Obsidian | Level 7

hi i have data with 4 variables:

 

year, month,company, return

 

i want to compound the monthly return to annual. so that for each year:

(1+january return)*(1+feb return).....*(1+dec return)

 

does anyone know a smart way to do this?

 

many thanks!

 

 

 

5 REPLIES 5
Ksharp
Super User

data and output ?

aarony
Obsidian | Level 7
Could u be a bit more specific? Thx so mcuh!!
Reeza
Super User

@aarony wrote:
Could u be a bit more specific? Thx so mcuh!!



@PGStats is stating that your question is unclear and asking if you can provide sample input data with matching output so your problem can be easily understood.  In other words, can you be more specific about your question 🙂

PGStats
Opal | Level 21

Try

 

proc sql;
create table compound as
select 
	company, 
	year, 
	exp(sum(log(1+return))) - 1 as compoundedReturn
from myData
group by company, year;
quit;
PG
JohndeKroon
Obsidian | Level 7

Hi,

 

I just made a small assumption on how your data would look like given your request! First I used a transpose (1 line per company per year, with an entry for each month). Then I used a data step icw array-function to determine the yearly return:

 

data input (drop =  i);
	format company $13.;
	do i = 1 to 12;
		year = 2016;
		month = i;
		company = 'A';
		return = i/100;
		output;
		company = 'B';
		return = (i+1)/100;
		output;
	end;
run;

proc sort data=input out=sortedInput;
	by year company month;
run;

proc transpose date=sortedInput out=tInput prefix=M;
	by company year;
	id month;
run;

data output (drop=i);
	set tInput;
	array allMonths(12) M1-M12;
	yearReturn = 1;
	do i = 1 to dim(allMonths);
		yearReturn = yearReturn*(1+allMonths[i]);
	end;
	yearReturn = yearReturn -1;
run;

 

Hope this helps.

 

John

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1028 views
  • 0 likes
  • 5 in conversation