BookmarkSubscribeRSS Feed
joon1
Quartz | Level 8

Dear Madam/Sir,

I would like to construct annual buy and hold returns in each fiscal year (eleven month ahead of closemonth and closemonth) using monthly return files and try an example code in this forum.

I see the following error message. Any help will be highly appreciated.  Thanks. Joon1.

data c4;
set c3;
 by permno;
 if _n_=1 then do until;

ERROR 22-322: Syntax error, expecting one of the following: (, =.

ERROR 76-322: Syntax error, statement will be ignored.

 array {1979:2019,1:12} _temporary_ ;
ERROR: Undeclared array referenced: array.
ERROR 22-322: Syntax error, expecting one of the following: <, <=, =, >, >=, EQ, GE, GT, LE, LT,
NE, NG, NL, ^=, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

 array logplusone {12} _temporary_;
 y=year(date);
 m=month(date);
 logplusone{m}=log(1+ret);
 if closemonth^=.;
 if n(of logplusone{*})=12 then annualbhr=exp(sum(of logplusone{*}));
run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C4 may be incomplete. When this step was stopped there were 0
observations and 34 variables.

 

The data form is below.

11000119900131.-0.0185
21000119900228.-0.0063
31000119900330.0.01266
41000119900430.0
51000119900531.-0.0127
61000119900629.0.0141
71000119900731.0.02564
81000119900831.-0.05
91000119900928.0.04079
101000119901031.-0.0128
111000119901130.0
121000119901231120.0013
 permnodateclosemonthret
5 REPLIES 5
andreas_lds
Jade | Level 19

The problem may be caused by skipping the condition in the until-statement in

 if _n_=1 then do until;

Try something like

if _n_ = 1 then do;
  do until (INSERT_CONDITION);
    ...
  end;
end;

To increase the readability of you post, please use "insert SAS code" (the running man icon) and "insert code" for logs. Posting data in usable form is highly recommended if you want/expect tested code in answers.

joon1
Quartz | Level 8

Thank you for your reply, Andreas.

I used the following code and test data is attached (csv file).


data c4;
set c3;
by permno;
if _n_=1 then do until (end_of_annualbhr);
set ret end=end_of_annualbhr;
array annualbhr {1990:2019,1:12} _temporary_ ;
array logplusone {12} _temporary_;
y=year(date);
m=month(date);
logplusone{m}=log(1+ret);
if closemonth^=.;
if n(of logplusone{*})=12 then annualbhr=exp(sum(of logplusone{*}));
end;
run;

 

And I had the following error message.

241 data c4;
242 set c3;
243 by permno;
244 if _n_=1 then do until (end_of_annualbhr);
245 set ret end=end_of_annualbhr;
ERROR: File WORK.RET.DATA does not exist.
246 array annualbhr {1990:2019,1:12} _temporary_ ;
247 array logplusone {12} _temporary_;
248 y=year(date);
249 m=month(date);
250 logplusone{m}=log(1+ret);
251 if closemonth^=.;
252 if n(of logplusone{*})=12 then annualbhr=exp(sum(of logplusone{*}));
ERROR: Illegal reference to the array annualbhr.
253 end;
254 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C4 may be incomplete. When this step was stopped there were 0
observations and 33 variables.

 

Any help will be highly appreciated.

Thank you

Joon1

 

andreas_lds
Jade | Level 19

In the line

if n(of logplusone{*})=12 then annualbhr=exp(sum(of logplusone{*}));

you are using annualbhr as variable, but it is an array, so you have to change it to something like

if n(of logplusone{*})=12 then annualbhr{y,m}=exp(sum(of logplusone{*}));
joon1
Quartz | Level 8

Thanks for your help. I tried the following code and still have an error message. It will be appreciative if you can advise me how to make do loop in the first two lines of the program. Thanks.

data c4;
set c3;
by permno;
if _n_=1 then do until (end_of_annualreturn);
set annualreturn end=end_of_annualreturn;
array annualbhr {1990:2019,1:12} _temporary_ ;
array logplusone {12} _temporary_;
y=year(date);
m=month(date);
logplusone{m}=log(1+ret);
if closemonth^=.;
if n(of logplusone{*})=12 then annualbhr{y,m}=exp(sum(of logplusone{*}));
end;
run;

 

error message

 

435 data c4;
436 set c3;
437 by permno;
438 if _n_=1 then do until (end_of_annualreturn);
439 set annualreturn end=end_of_annualreturn;
ERROR: File WORK.ANNUALRETURN.DATA does not exist.
440 array annualbhr {1990:2019,1:12} _temporary_ ;
441 array logplusone {12} _temporary_;
442 y=year(date);
443 m=month(date);
444 logplusone{m}=log(1+ret);
445 if closemonth^=.;
446 if n(of logplusone{*})=12 then annualbhr{y,m}=exp(sum(of logplusone{*}));
447 end;
448 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C4 may be incomplete. When this step was stopped there were 0
observations and 33 variables.
WARNING: Data set WORK.C4 was not replaced because this step was stopped.

andreas_lds
Jade | Level 19

Please post logs using the "insert code" button and code using the "insert sas code" button, won't debug unformatted code. But the error-message you get is quite easy to understand: ERROR: File WORK.ANNUALRETURN.DATA does not exist.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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