*我们的SAS老师也给出了一个类似题目的答案,但是运行的时候有个地方有错误,希望大家能帮忙纠正,谢谢!代码如下;
%macroget_hist_quote(instrument=msft,start='01jan2000'd,end=,out=) ;
%localinstrument start end;
%locals a b c d e f g q y z x url;
%if(%superq(instrument)eq ) %then
%letinstrument=msft;
%letinstrument=%lowcase(&instrument);
%if(%superq(end) eq ) %then
%letend=%str(%')%sysfunc(today(),date9.)%str(%'d);
%if(%superq(start) eq ) %then
%letstart='01jan2000'd;
%if(%superq(out) eq ) %then
%letout=inst_%sysfunc(compress(&instrument,%str(-./^)));
%lets=&instrument;
%leta=%sysfunc(month(&start));
%let a=%eval_r(&a-1);
%letb=%sysfunc(day(&start));
%if &b < 10 %then %let b=0&b;
%letc=%sysfunc(year(&start));
%letd=%sysfunc(month(&end));
%let d=%eval_r(&d-1);
%lete=%sysfunc(day(&end));
%if&e < 10 %then %let e=0&e;
%letf=%sysfunc(year(&end));
%letg=d;
%letq=q;
%lety=0;
%letz=&s;
%letx=.csv;
%letand=%str(&);
%let url=http://ichart.finance.yahoo.com/table.csv;
%leturl=&url.?s=&s;
%leturl=&url.&and.d=&d.&and.e=&e.&and.f=&f;
%leturl=&url.&and.g=&g;
%leturl=&url.&and.a=&a.&and.b=&b.&and.c=&c;
%leturl=&url.&and.ignore=.csv;
%put&url;
data_null_;
numb= ceil (ranuni(0)*10000000);
r= 'A' || put(numb, Z7.);
callsymput ('ran', r);
run;
filenamemyquote url "&url";
data&ran;
infilemyquote dlm=',' dsd firstobs=2;
informatDate yymmdd10. ;
formatDate yymmdd10. ;
retaininstrument "&instrument";
inputdate
Open
High
Low
Close
Volume
Adj_Close;
procsql;
createtable &out as
selectdistinct *
from&ran
wherevolume ^= 0
orderby date;
quit;
odsselect none;
procdatasets;
delete&ran;
run;
odsselect all;
%mend get_hist_quote;
%get_hist_quote(instrument=600196.SS,start='01jan1991'd,end=,out=);