SAS中文论坛

标题: 求助在SAS9.2版macro下运行的sql命令的问题 [打印本页]

作者: shiyiming    时间: 2010-5-2 12:04
标题: 求助在SAS9.2版macro下运行的sql命令的问题
这是我的code:
proc sql;
create table d_cash as

select

d_all.permno,

d_all.ret,
d_all.beta,
d_all.month,
d_cash.cash_holding_prev_year as cash_holding,
(d_all.ret-d_all.alpha-d_all.beta*d_all.month_mkt_ret) as ab_ret
from
d_cash left join d_all
on
d_cash.permno=d_all.permno
and
49<=i<=60
order by
permno, month;

data d_cash;
set d_cash;
if 0<cash_holding<0.20
then
sample=1;
else
if
cash_holding>=0.20
then
sample=2;
else
sample=0;

这是log里的报错:
MPRINT(CASH_STUDY):  proc sql;
NOTE: Line generated by the invoked macro "CASH_STUDY".
11    's cash holding;data d_cash;set d_cash_holding;where year(date)=&year_cycle;run;proc sql;
11  ! create table d_cash
11  ! asselectd_all.permno,d_all.ret,d_all.beta,d_all.month,d_cash.cash_holding_prev_year as
      -------------
      79
11  ! cash_holding,
ERROR 79-322: Expecting a LIKE.

NOTE 137-205: Line generated by the invoked macro "CASH_STUDY".
11    's cash holding;data d_cash;set d_cash_holding;where year(date)=&year_cycle;run;proc sql;
11  ! create table d_cash
11  ! asselectd_all.permno,d_all.ret,d_all.beta,d_all.month,d_cash.cash_holding_prev_year as
                          -
                          22
11  ! cash_holding,
ERROR 22-322: Syntax error, expecting one of the following: (, AS, LIKE.

NOTE: Line generated by the invoked macro "CASH_STUDY".
11    's cash holding;data d_cash;set d_cash_holding;where year(date)=&year_cycle;run;proc sql;
11  ! create table d_cash
11  ! asselectd_all.permno,d_all.ret,d_all.beta,d_all.month,d_cash.cash_holding_prev_year as
                          -
                          200
11  ! cash_holding,
ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE 137-205: Line generated by the invoked macro "CASH_STUDY".
11    's cash holding;data d_cash;set d_cash_holding;where year(date)=&year_cycle;run;proc sql;
11  ! create table d_cash
11  ! asselectd_all.permno,d_all.ret,d_all.beta,d_all.month,d_cash.cash_holding_prev_year as
                                                                                          --
                                                                                          22
11  ! cash_holding,
ERROR 22-322: Syntax error, expecting one of the following: ;, (, ','.

NOTE: Line generated by the invoked macro "CASH_STUDY".
11    's cash holding;data d_cash;set d_cash_holding;where year(date)=&year_cycle;run;proc sql;
11  ! create table d_cash
11  ! asselectd_all.permno,d_all.ret,d_all.beta,d_all.month,d_cash.cash_holding_prev_year as
                                                                                          --
                                                                                          76
11  ! cash_holding,
ERROR 76-322: Syntax error, statement will be ignored.

MPRINT(CASH_STUDY):  create table d_cash asselectd_all.permno,,
,d_all.month,d_cash.cash_holding_prev_year as
cash_holding,(-d_all.alpha-d_all.beta*d_all.month_mkt_ret) as ab_retfromd_cash left join
d_allond_cash.permno=d_all.permnoand49<=i<=60order bypermno, month;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds



NOTE: Line generated by the invoked macro "CASH_STUDY".
12    data d_cash;set d_cash;if 0<cash_holding<0.20thensample=1;

----------
-

1
180

------------------

180
12  ! elseifcash_holding>=0.20thensample=2
MPRINT(CASH_STUDY):  data d_cash;
MPRINT(CASH_STUDY):  set d_cash;
MPRINT(CASH_STUDY):  if 0<cash_holding<0.20thensample=1;
MPRINT(CASH_STUDY):  elseifcash_holding>=0.20thensample=2;
MPRINT(CASH_STUDY):  elsesample=0;
MPRINT(CASH_STUDY):  retain sample;

WARNING 1-322: Assuming the symbol THEN was misspelled as thensample.

ERROR 180-322: Statement is not valid or it is used out of proper order.

貌似是分不出as select以及把
then 语句和变量sample 当成了thensample这个变量。
总之,有点长,谢谢知情人的回答。
作者: shiyiming    时间: 2010-5-2 12:34
标题: Re: 求助在SAS9.2版macro下运行的sql命令的问题
log第3行
[code:26lt1lk2]11 's cash holding;data d_cash;set d_cash_holding;where year(date)=&year_cycle;run;proc sql;[/code:26lt1lk2]
[quote:26lt1lk2]'s cash holding;[/quote:26lt1lk2]
是什么东西?
作者: shiyiming    时间: 2010-5-2 13:11
标题: Re: 求助在SAS9.2版macro下运行的sql命令的问题
sorry
在sql之前还有一个data step没有读出来:

data d_cash;
set d_cash_holding;
where year(date)=&year_cycle;
run;

proc sql;
create table d_cash as
…………等等如上
作者: shiyiming    时间: 2010-5-2 14:11
标题: Re: 求助在SAS9.2版macro下运行的sql命令的问题
[quote:3v3rf2pv]'s cash holding;[/quote:3v3rf2pv]
这半句是怎么来的? 从%macro CASH_STUDY; 到data d_cash;之间还有什么?




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2