04-18-2016 04:07 AM
Using SAS 9.4, I want to calculate compound company stock returns following intermittent director trades. Many companies have director trades on consecutive days or several days apart, yet the compounding period extends up to 60 days.
There are 2 compounding periods for the calculation of returns:
A simplified data sample looks like this:
AAA (up to 1,500 observations)
(similar data to AAA)
date = trading date: thinly traded stocks have missing dates – no trade means no observation.
Return+1 = value of stock return plus 1. Return value may be for a period of more than one day.
director_tradeID = = signals a director’s trade
trade_announcement_date = usually up to 6 days after trading date.
return_count = the number of days between consecutive observations
My preliminary code for calculating compound returns up to 60 observations from the date of director trade, and the error messages, are as follows:
Data returns2 ;
By company date;
if (director_tradeID ' ') then do;
x = _n_ ;
y = (_n_ + 60);
call symputx ('firstobserv', x);
call symputx ('observ', y);
Set returns (firstobs = &firstobserv obs = &observ ) ;
if first.company then do;
compoundreturn_plus1 = 1;
compoundreturn_daycount = 0;
compoundreturn_plus1 = (compoundreturn_plus1 * return);
compoundreturn_daycount = (compoundreturn_daycount + return_count);
Retain compoundreturn_plus1 compoundreturn_daycount;
The identical error messages for the firstobs and obs options are:
ERROR 23-7: Invalid value for FIRSTOBS option
ERROR: Invalid number conversion on &.
WARNING: Apparent symbolic reference FIRSTOBSERV not resolved.
NOTE: The SAS System stopped processing this step because of errors.
Proc sql methods to calculate returns may be more efficient, so I’m open to alternate suggestions.
04-18-2016 04:15 AM
The macro variables within call symput functions can not be used in the same data step.
Please read the section
Problem Trying to Reference a SYMPUT-Assigned Value Before It Is Available
from this link: