Hi, I am trying to run the RESTATEMENT SAS code

http://www.wrds.us/index.php/tutorial/view/restatement_event_study

However, I met a problem when I was doing the CAR’s part:

Original code:

/* compute CAR’s */

data myLib2.n_CAR (keep = key r_3day car_vw counter alpha beta );

set myLib2.m_withdailyIndex;

/* by key means that it will run through these statements for each key,

where key is a unique identifier of one observation

*/

by key;

/* retain means that the contents of these variables will be available

for example, counter will be set to zero with every observation

with every row of data (return), it will increase by 1

“if last.key then output” will write the value of the counter to the newly

created dataset

r_3day: 1 + 3 days of returns

car_vw: 3-day cumulative abnormal return

*/

retain counter r_3day car_vw;

if first.key then counter=0;

if first.key then car_vw=1;

if first.key then r_3day=1;

if ret eq . then ret = 0;

counter+1;

/* cumulative abnormal return */

car_vw = car_vw + ret - (alpha+beta * vwretd);

/* raw return, 3 day cumulative */

r_3day = r_3day + ret;

/* we are only interested in keeping the cumulative 3 day return (and not

cumulative 1 and 2 day) */

if last.key then output;

run;

my log result:

ERROR: BY variables are not properly sorted on data set WORK.M_WITHDAILYINDEX.

DATE=19970415 vwretd=0.011996 PERMNO=10187 RET=0.000000 press_date=04/16/1997 key=13620_HPLX

alpha=0.0062112012 beta=1.0203537358 FIRST.key=1 LAST.key=1 counter=1 r_3day=1.0730593577

car_vw=1.0629233614 _ERROR_=1 _N_=15

NOTE: The SAS System stopped processing this step because of errors.

NOTE: There were 16 observations read from the data set WORK.M_WITHDAILYINDEX.

WARNING: The data set WORK.N_CAR may be incomplete. When this step was stopped there were 6

observations and 6 variables.

NOTE: DATA statement used (Total process time):

real time 0.03 seconds

cpu time 0.03 seconds

Can anyone help me to find my mistake?

Thanks.