我有一段代码连接到远程服务器,将一些变量传递给它,然后查询服务器上的数据,然后对其进行操作。这段代码完全按照我的预期工作,产生了我需要的数据。
但是,我需要在宏循环中运行代码。这就是一切都崩溃的地方。我不确定问题是什么,但我怀疑这是某种变量范围问题。我试图在网上研究这样做,但无法弄清楚。
问题出现在data xtemp2
块中。当我尝试运行它时,我收到以下错误:
WARNING: Apparent symbolic reference INTERVAL_SECONDS not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name,
a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
和
WARNING: Apparent symbolic reference START_TIME not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name,
a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
另请注意,我有时会收到与rtime
、iprice
、oprice
和类似的错误itime
。再一次,当我自己运行这段代码时,它运行得很好。将其放入带有循环的宏中似乎会产生这些问题,这让我觉得我没有正确初始化这些变量。我非常感谢您提供的任何见解和提示。
%macro getthedata(nrows,ystart,yend); *nrows is the number of rows in the text file;
%do i=1 %to &nrows;
%do m=&ystart %to ¥d;
(...)
signon username=_prompt_;
%syslput VAR1 = &var1;
%syslput M = &m;
rsubmit;
libname abc'/data/sasdata'; *Thisis where the datasets are located;
%let start_time = '9:30:00't; * starting time;
%let interval_seconds =15*60; * interval is 15*60 seconds, 15min;
data all2009;
set sas.a_&M.01:;
by symbol date time;
where symbol = &VAR1 and time between '9:30:00't and '16:00:00't;
run;
data xtemp2;
set all2009;
by symbol date time;
format itime rtime time12.;
if first.symbol=1 or first.date=1 then do;
*Initialize time and price when new symbol or date starts;
rtime=time;
iprice=bid;
oprice=ofr;
itime=&start_time;
end;
if time >= itime then do; *Intervalreached;
output; *rtime and iprice hold the last observation values;
itime = itime +&interval_seconds;
do while(time >= itime); *need to fill in alltime intervals;
output;
itime = itime +&interval_seconds;
end;
end;
rtime=time;
iprice=bid;
oprice=ofr;
retain itime rtime iprice oprice; *Carry time and price valuesforward;
*keep symbol date itime iprice rtime;
run;
proc download data=all2009 out=local.all30 (keep=SYMBOL DATE PRICE SIZE itime);
run;
endrsubmit;
(...)
%end;
%end;
%mend getthedata;
Options MPRINT;
%getthedata(3,2007,2007)
解决方案(根据乔的回答)
我能够使用乔发布的解决方案成功创建interval_seconds
和start_time
变量。%NRSTR
这是相关的修改代码部分:
(...)
signon username=_prompt_;
%syslput VAR1 = &var1;
%syslput M = &m;
rsubmit;
libname abc'/data/sasdata'; *Thisis where the datasets are located;
%nrstr(%%)let start_time = '9:30:00't; * CHANGED LINE;
%nrstr(%%)let interval_seconds =15*60; * CHANGED LINE;
data all2009;
set sas.a_&M.01:;
by symbol date time;
where symbol = &VAR1 and time between '9:30:00't and '16:00:00't;
run;
(...)