2016-05-31 26 views
2

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

回答

2

下面的代码应解释如何(库mylib在这种情况下)的FMTSEARCH选项,指定哪个库中搜索SAS格式添加库:

/* 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到图书馆,您的格式目录是,并且这应该解决格式错误并允许您显示格式化的数据。

+0

什么时候将'options append ='添加到SAS?它在9.1.3中不起作用。 – user667489

+0

@ user667489看起来像9.2,因为它在9.2的文档中。 – Joe

+0

这对我来说也是一个新的! – mjsqu

1

对于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)); 

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