BookmarkSubscribeRSS Feed
tangotrain
Calcite | Level 5

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:

  1. Until the director-trade announcement date plus one day, usually up to 6 days.
  2. 60 days after the director trade.

 

A simplified data sample looks like this:

 

Company

date

director_tradeID

Return+1

trade_announcementdate

return_count

AAA

30APR2010

 

1

 

0

AAA

3MAY2010

a

1

06MAY2010

3

AAA

4MAY2010

 

1

 

1

AAA

05MAY2010

b

1.01

05MAY2010

1

AAA

06MAY2010

c

0.98

12MAY2010

1

AAA

7MAY2010

 

0.88

 

1

AAA

10MAY2010

 

1.22

 

3

AAA (up to 1,500 observations)

   

 

 

 

 

 

AAB

     

AAB

     

(similar data to AAA)

 

Where:

company

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 ;

Set returns;

By company date;

if (director_tradeID ' ') then do;

x =  _n_  ;

y = (_n_ + 60);

end;

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;

End;

 

Else do;

compoundreturn_plus1 = (compoundreturn_plus1 * return);

compoundreturn_daycount  = (compoundreturn_daycount  + return_count);

 

End;

Retain compoundreturn_plus1 compoundreturn_daycount;

Run;

 

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.

Many thanks,

TT. 

1 REPLY 1
Loko
Barite | Level 11

Hello,

 

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:

 

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000210266.htm

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
  • 1 reply
  • 936 views
  • 1 like
  • 2 in conversation