【问题标题】:Download Data From TAQ Using SAS使用 SAS 从 TAQ 下载数据
【发布时间】:2013-07-14 01:30:15
【问题描述】:

我正在尝试使用 SAS 在 WRDS 上下载整个 TAQ 数据库。以下是WRDS技术支持人员给出的SAS代码:

%let wrds=wrds.wharton.upenn.edu 4016;
options comamid=TCP remote=WRDS;
signon username=_prompt_;

%macro taq_daily_dataset_list(type=ctm,begyyyymmdd=20100101,endyyyymmdd=20111231) / des="Autogenerated list of needed Daily TAQ datasets";
    %let type=%lowcase(&type);
    /* Get SAS date values for date range endpoints */
    %let begdate = %sysfunc(inputn(&begyyyymmdd,yymmdd8.));
    %let enddate = %sysfunc(inputn(&endyyyymmdd,yymmdd8.));
        %do d=&begdate %to &enddate /** For each date in the DATE range */;
            %let yyyymmdd=%sysfunc(putn(&d,yymmddn8.));
            /*If the corresponding dataset exists, add it to the list */
            %if %sysfunc(exist(taqmsec.&type._&yyyymmdd)) %then taqmsec.&type._&yyyymmdd;
        %end;
%mend;

* using this macro;
data my_output;
  set %taq_daily_dataset_list(type=ctm,begyyyymmdd=20100101,endyyyymmdd=20121231) open=defer;
run;

我试图在 SAS 中运行它,但它给了我一个错误“没有默认输入数据集 (_LAST_IS_NULL)”。我不知道如何使用SAS,甚至一点也不知道。我想要的只是下载数据库。

如果有人能帮助我离开这里,我真的很感激。

【问题讨论】:

  • 该错误与您的代码不一致。唯一明显错误的是您没有定义 libname taqmsec,但这可能发生在 tcp 文件中。但是,您可能需要获取 tcp 连接脚本。不管怎样,这个错误意味着你有类似 proc 排序(或任何 proc)的东西,没有 data= 参数。

标签: sas wrds


【解决方案1】:

您正在运行的代码是从您的计算机到远程服务器的 SAS/CONNECT 会话。连接后,我假设在服务器上定义了 libname TAQMSEC。所以,我猜你需要“远程提交”代码(这将在服务器的 WORK 库中创建 SAS 数据集my_output)。然后你可以使用PROC DOWNLOAD将它复制到你的本地机器:

%let wrds=wrds.wharton.upenn.edu 4016;
options comamid=TCP remote=WRDS;
signon username=_prompt_;

RSUBMIT; /* Execute following on server after logging in */

%macro taq_daily_dataset_list(type=ctm,begyyyymmdd=20100101,endyyyymmdd=20111231) / des="Autogenerated list of needed Daily TAQ datasets";
    %let type=%lowcase(&type);
    /* Get SAS date values for date range endpoints */
    %let begdate = %sysfunc(inputn(&begyyyymmdd,yymmdd8.));
    %let enddate = %sysfunc(inputn(&endyyyymmdd,yymmdd8.));
        %do d=&begdate %to &enddate /** For each date in the DATE range */;
            %let yyyymmdd=%sysfunc(putn(&d,yymmddn8.));
            /*If the corresponding dataset exists, add it to the list */
            %if %sysfunc(exist(taqmsec.&type._&yyyymmdd)) %then taqmsec.&type._&yyyymmdd;
        %end;
%mend;

* using this macro;
data my_output;
  set %taq_daily_dataset_list(type=ctm,begyyyymmdd=20100101,endyyyymmdd=20121231) open=defer;
run;

/* Download result to your computer */
proc download data=my_output;
run;

ENDRSUBMIT; /* Signals end of processing on remote server */

出现在RSUBMITENDRSUBMIT 命令之间的任何编程语句都在远程服务器上执行。请注意,宏是由远程 SAS 会话创建和执行的。

检索到所需数据后,记得使用signoff命令断开与服务器的连接。

【讨论】:

    【解决方案2】:

    我不会说 SAS,因此无法评论您的代码,但我不认为“taqmsec”是主要文件之一。合并交易数据保存在格式为 taq.CT_YYYYMMDD 的文件中,合并报价文件为 taq.CQ_YYYYMMDD。这些的第一个可用日期是 19930104。

    当我有一个帐户时,我编写了一些 Python 脚本来自动化从 WRDS 批量下载数据的过程:https://github.com/jbrockmendel/pywrds

    尝试自动设置 SSH 密钥的脚本未经测试(如果您想帮助我测试/修复它们,请给我发消息),但核心已经过良好测试。假设您设置了帐户和基于密钥的身份验证,您可以运行:

    import pywrds
    
    # Download the TAQ Consolidated Trades (TAQ_CT) file for 1993-06-12.
    # y = [num_files, num_rows, paramiko_ssh, paramiko_sftp, time_elapsed]
    
    y = pywrds.get_wrds('taq.ct', 1993, 06, 12) 
    
    # Loop over all available dates to download in bulk.
    # The script is moderately smart about picking up 
    # unfinished loops where they left off.
    # y = [num_files, time_elapsed]
    
    y = pywrds.wrds_loop('taq.ct')
    
    # Find out what the darn names of the available TAQ files are.
    # y = [file_list, paramiko_ssh, paramiko_sftp]
    
    y = pywrds.find_wrds('taq')
    

    文件从 1993 年的每个几十 MB 开始,taq.ct 增长到每个约 1 GB,taq.cq 增长到 >5GB。标准 WRDS 帐户将您的存储空间限制为 1 GB,因此尝试查询所有内容,例如 taq.cq_20050401 将在您的目录中放置一个截断的文件。 pywrds.get_wrds 分解这些大查询并循环遍历较小的文件,然后在它们全部下载后重新组合它们。

    注意:下载后,wrds_loop 也会从服务器上的目录中删除这些文件。它还运行rm wrds_export*,因为它上传的所有 SAS 文件都以“wrds_export”开头。确保您没有其他任何遵循相同模式的内容。

    同样的命令也适用于 Compustat (comp.fundq, comp.g_fundq, ...), CRSP (crsp.msf, crsp.dsf, ...), OptionMetrics (optionm.optionm_opprcd1996, optionm.opprcd1997,. ..)、IBES、TFN、...

    # Also works with other WRDS datasets.
    # The day, month, and year arguments are optional.
    
    # Get the OptionMetrics pricing file for March 1993
    y = pywrds.get_wrds('optionm.opprcd', 1993, 3)
    
    # Get the Compustat Fundamentals Quarterly file for 1997
    y = pywrds.get_wrds('comp.fundq', 1997)
    
    # Get the CRSP Monthly Stock File for all available years
    y = pywrds.get_wrds('crsp.msf')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-05
      • 2017-10-07
      • 2017-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多