我正在尝试编写一个函数,该函数将获取日期列表并检索https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm上找到的数据集。
我在SAS中使用PROC IML来执行R代码(因为我对R比较熟悉)。
我的问题是在R,是由于该网站。
首先,我知道有一个API,但这是我真正想要学习的练习,因为很多网站都没有API。
有人知道如何检索数据集吗?
我听说过的事:
我已经找了一整天的解决办法,但都没有用!请帮帮忙
发布于 2018-05-15 19:50:22
您可以使用Proc HTTP
在SAS会话中执行相同的http处理。CSV数据不包含标题行,因此XML格式可能更合适。美国国债直销网站有几个注意事项。
<bpd>
,SAS XMLV2库引擎不能简单地处理这些标记容器。这个额外的标记可以通过一些数据步骤处理来删除。XML示例代码
filename response TEMP;
filename respfilt TEMP;
* Get request sets up fresh session and cookies;
proc http
clear_cache
method = "get"
url ="https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm"
;
run;
* Post request as performed by XML format button;
* automatically utilizes cookies setup in GET request;
* in= can now directly specify the parameter data to post;
proc http
method = "post"
in = 'priceDate.year=2018&priceDate.month=5&priceDate.day=15&submit=XML+Format'
url ="https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm"
out = response
;
run;
* remove bpd tag from the response (the downloaded xml);
data _null_;
infile response;
file respfilt;
input;
if _infile_ not in: ('<bpd', '</bpd');
put _infile_;
run;
* copy data collections from xml file to tables in work library;
libname respfilt xmlv2 ;
proc copy in=respfilt out=work;
run;
参比物质
使用SAS轻松休息:如何使用SAS来获得REST 约瑟夫·亨利( Joseph Henry ),SAS研究所公司,卡里,NC http://support.sas.com/resources/papers/proceedings16/SAS6363-2016.pdf
https://stackoverflow.com/questions/50360882
复制