【发布时间】:2016-05-31 05:07:20
【问题描述】:
我已经下载了一个 sas 数据集和一个与之配套的格式目录。这可能是超级基本的,但我似乎无法设置库以便我可以使用这些格式,并且除非我使用 NOFMTERR 选项,否则我无法打开数据集。它们都在同一个windows文件夹中。请帮忙。
【问题讨论】:
标签: sas
我已经下载了一个 sas 数据集和一个与之配套的格式目录。这可能是超级基本的,但我似乎无法设置库以便我可以使用这些格式,并且除非我使用 NOFMTERR 选项,否则我无法打开数据集。它们都在同一个windows文件夹中。请帮忙。
【问题讨论】:
标签: sas
以下代码应说明如何将库(在本例中为库 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 中不起作用。
对于 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));
当然,如果您多次运行,这将多次重新附加该值;这无害,但可能看起来很奇怪。您可以做一些额外的检查以查看它是否已经在字符串中,如果是则不要重新添加。
【讨论】: