我有一段代碼連接到遠程服務器,將一些變量傳遞給它,然後查詢服務器上的數據,然後操縱它。此代碼完全按照我的預期工作,生成我需要的數據。SAS - 在放入宏(遠程服務器)時無法獲取代碼工作
但是,我需要在宏循環中運行代碼。這是一切破裂的地方。我不確定問題是什麼,但我懷疑它是某種可變範圍問題。我試圖在網上進行研究,但無法弄清楚。
該問題發生在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)
SOLUTION(每喬的回答)
我是能夠成功地創建使用%NRSTR
解決方案喬張貼interval_seconds
和start_time
變量。
下面是相關修改後的代碼段:
(...)
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;
(...)
沒有跟大家展示一下一個範圍問題。在RSUBMIT裏面,沒有宏正在運行,所以沒有範圍問題 - 這是一個全局變量。除非你沒有告訴我們關於&interval_seconds的信息,否則我沒有理由明白爲什麼會發生這種情況。 – Joe
我想補充說,這可能不是一個很好的解決您的整體問題。您可以在沒有宏循環的情況下解決問題,尤其是不需要重複提交;這似乎可以通過適當構建的大型數據集和BY語句來解決,如果您反覆運行循環,這可能會更有效。 – Joe
我這樣循環的原因是我想一次拉一小部分數據(「小」仍然是數百MB)。你能否提供更多關於實際錯誤的含義?是否說變量是空白的? –