然后出现错误:
[color=#FF0000:2viia1v4]ERROR: The %IF statement is not valid in open code.
MPRINT(CASH): data worklib.d_cash_study;
MPRINT(CASH): set d_cash;
ERROR: The %END statement is not valid in open code.
ERROR: The %ELSE statement is not valid in open code.[/color:2viia1v4]
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORKLIB.D_CASH_STUDY may be incomplete. When this step was stopped there
were 0 observations and 7 variables.
WARNING: Data set WORKLIB.D_CASH_STUDY was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
NOTE: Appending WORK.D_CASH to WORKLIB.D_CASH_STUDY.
NOTE: There were 10178 observations read from the data set WORK.D_CASH.
NOTE: 10178 observations added.
NOTE: The data set WORKLIB.D_CASH_STUDY has 122136 observations and 7 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
[color=#FF0040:2viia1v4]
ERROR: The %END statement is not valid in open code.[color=#FF0000][/color:2viia1v4]
ERROR: The %END statement is not valid in open code.
ERROR: No matching %MACRO statement for this %MEND statement.[/color]
%*Get monthly market return;
proc sql;
create table d as
select
d_ff.*,
(year(d_ff.date)*100+month(d_ff.date)) as month
from
d_ff
where
&year_cycle-4<=year(d_ff.date)<=&year_cycle;
%*Number of months;
proc sort data=d out=d_months (keep=month) nodupkeys;
by month;
data d_months;
set d_months;
i+1;
proc sort data=d_months;
by month;
%*Compute average return of all stocks as proxy for monthly market return;
proc sort data=d;
by month;
proc means data=d noprint;
by month;
output out=d_mkt_ret
mean(ret)=month_mkt_ret;
proc sort data=d_mkt_ret (keep=month month_mkt_ret);
by month;
data d;
merge
d_mkt_ret(keep=month month_mkt_ret)
d_months(keep=i month);
by month;
proc sort data=d nodupkeys;
by month;
%*Merge market return and stock return;
proc sql;
create table d_1 as
select
d_ff.permno,
d_ff.ret,
(year(d_ff.date)*100+month(d_ff.date)) as month
from
d_ff
where
&year_cycle-4<=year(d_ff.date)<=&year_cycle;
proc sort data=d_1;
by month;
data d_all;
merge
d_1(keep=permno month ret)
d(keep=month i month_mkt_ret);
by month;
%*Keep only securities with returns in all 12 months;
proc sort data=d_all;
by permno;
proc means data=d_all noprint;
var ret;
output out=d_all_stats_1 n=n_1;
by permno;
where
1<=i<=48;
proc means data=d_all noprint;
var ret;
output out=d_all_stats_2 n=n_2;
by permno;
where
48+1<=i<=48+12;
data d_all_1;
merge
d_all d_all_stats_1 d_all_stats_2;
by permno;
if
n_1=48 and n_2=12;
%*Compute betas for firms;
proc reg data=d_all_1 outest=d_all_reg (keep=intercept month_mkt_ret permno) noprint;
model ret=month_mkt_ret;
by permno;
where
1<=i<=48;
run;
data d_all_reg (rename=(intercept=alpha month_mkt_ret=beta));
set d_all_reg;
data d_all;
merge
d_all_1 d_all_reg;
by permno;
data d_all;
set d_all;
drop n_1 n_2 _type_ _freq_;
%*Define portfolio according to company's cash holding;
data d_cash_holding_1;
set d_cash_holding;
where
year(date)=&year_cycle;
proc sort data=d_cash_holding_1 (keep=permno cash_holding_prev_year) nodupkeys;
by permno;
proc sql;
create table d_cash as
select
d_all.permno,
d_all.ret,
d_all.beta,
d_all.month,
d_cash_holding_1.cash_holding_prev_year as cash,
(d_all.ret-d_all.alpha-d_all.beta*d_all.month_mkt_ret) as ab_ret
from
d_cash_holding_1 left join d_all
on
d_cash_holding_1.permno=d_all.permno
and
48+1<=i<=48+12
order by
permno,month;
data d_cash;
set d_cash;
if 0<cash<0.20
then
sample=1;
else
if
cash>=0.20
then
sample=2;
else
sample=0;
retain sample;
proc sort data=d_cash;
by sample month;
%if &i=1 %then
%do;
data worklib.d_cash_study;
set d_cash;
%end;
%else
%do;
proc append base=worklib.d_cash_study data=d_cash;
run;
%end;
%end;
run;
%mend cash;作者: shiyiming 时间: 2010-5-3 10:55 标题: Re: Error: No matching %marco with this %mend 第113行,用后一种注释方式试试
[code:1kdafep4]%*Define portfolio according to company's cash holding;
/*Define portfolio according to company's cash holding*/[/code:1kdafep4]作者: shiyiming 时间: 2010-5-3 13:17 标题: Re: Error: No matching %marco with this %mend to hopewell
你好厉害啊。这么细弱的问题也可以找得到。
的确,雷同于*, %* 不能包含 ;和‘, 单引号和分号。
你给我看看这个问题
在GTL里,如何写出 x ^2? 就是x和一个superscript 2
如果在entry 里,写法类似于 "x"{sup "2"}.为什么写到x轴label里就不起作用了呢?比如
[code:395t5tyq]columnaxes;
columnaxis/griddisplay = on display = (label tickvalues) label = '"Change of X"{SUP "2"}';
endcolumnaxes;[/code:395t5tyq]作者: shiyiming 时间: 2010-5-3 14:45 标题: Re: Error: No matching %marco with this %mend 现在才看到大神给的回复,果然很强。
我也自己发现了这个问题了,居然被一个单引号搞了2天。。。
崩溃ing
谢谢各位的热心解答!!!作者: shiyiming 时间: 2010-5-3 21:02 标题: Re: Error: No matching %marco with this %mend To: 国际Su
好象是只能用于entry,瞎写一个,看看能用不
[code:3u1fct3l]data raw;
do x=1 to 4;
y1=ceil(3*ranuni(123));
y2=ceil(3*ranuni(123));
y3=ceil(3*ranuni(123));
y4=ceil(3*ranuni(123));
output;
end;
run;
proc template;
define statgraph test;
begingraph;
entrytitle "ScatterPlot";
layout lattice / rows=2 columns=2
rowdatarange=union columndatarange=union
rowgutter=2px columngutter=2px;
scatterplot x=x y=y1;
scatterplot x=x y=y2;
scatterplot x=x y=y3;
scatterplot x=x y=y4;
rowaxes;
rowaxis / griddisplay=on display=(tickvalues);
rowaxis / griddisplay=on display=(tickvalues);
endrowaxes;
columnaxes;
columnaxis / display=(tickvalues);
columnaxis / display=(tickvalues);
endcolumnaxes;
rowheaders;
entry "Rowheader1: Y "{sup "2"} / rotate=90;
entry "Rowheader2: Y "{sup "2"} / rotate=90;
endrowheaders;
columnheaders;
entry "ColumnHeader1: X "{sup "2"};
entry "ColumnHeader2: X "{sup "2"};
endcolumnheaders;
sidebar / align=left;
entry "SidebarLeft: Y "{sup "2"} / rotate=90;
endsidebar;
sidebar / align=bottom;
entry "SidebarBottom: X "{sup "2"};
endsidebar;
endlayout;
endgraph;
end;
run;
proc sgrender data=raw template=test;
run;[/code:3u1fct3l]作者: shiyiming 时间: 2010-5-3 23:11 标题: Re: Error: No matching %marco with this %mend to hopewell
A perfect example to illustrate how to use headers and sidbars. And the sidebar at bottom can exactly satisfy with me by replacing the -Y- label.
Cheers, JingJu