【问题标题】:How to match dataset with formats catalog in sas如何将数据集与 sas 中的格式目录匹配
【发布时间】:2016-05-31 05:07:20
【问题描述】:

我已经下载了一个 sas 数据集和一个与之配套的格式目录。这可能是超级基本的,但我似乎无法设置库以便我可以使用这些格式,并且除非我使用 NOFMTERR 选项,否则我无法打开数据集。它们都在同一个windows文件夹中。请帮忙。

【问题讨论】:

    标签: sas


    【解决方案1】:

    以下代码应说明如何将库(在本例中为库 mylib)添加到指定在哪些库中搜索 SAS 格式的 FMTSEARCH 选项:

    /* Display the current fmtsearch option - librefs searched in order for formats */
    %put %sysfunc(getoption(fmtsearch));
    
    libname mylib 'windows-folder';
    
    /* Append the library containing the format catalog */
    options append=(fmtsearch=mylib);
    
    /* Check the fmtsearch option again */
    %put %sysfunc(getoption(fmtsearch));
    

    只需将 SAS 指向您的格式目录所在的库,这应该可以解决格式错误并允许您显示格式化的数据。

    【讨论】:

    • options append= 何时添加到 SAS?它在 9.1.3 中不起作用。
    • @user667489 看起来像在 9.2 中,因为它在 9.2 的文档中。
    • 对我来说也是新的!
    【解决方案2】:

    对于 9.1.3 的用户,您可以直接更改 fmtsearch 选项。这是一种与上面@mjsqu 的代码最相似的方法(它保留了已经存在的格式选项)并附加到末尾。

    * Store fmtsearch option value in macro variable;
    %let fmtsearch=%sysfunc(getoption(fmtsearch));
    
    *Append NEWLIB to the end (assuming NEWLIB is your library name);
    *Uses SUBSTR to strip off the end parenthesis;
    %let fmtsearch_new = %substr(&fmtsearch,1,%length(&fmtsearch.)-1) NEWLIB);
    
    *Check new value;
    %put &fmtsearch_new;
    
    *Set fmtsearch option to new value;
    options fmtsearch=&fmtsearch_new.;
    
    *Check that option was set;
    %put %sysfunc(getoption(fmtsearch));
    

    当然,如果您多次运行,这将多次重新附加该值;这无害,但可能看起来很奇怪。您可以做一些额外的检查以查看它是否已经在字符串中,如果是则不要重新添加。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 2015-04-01
      • 2018-08-24
      相关资源
      最近更新 更多