Raf
Raf

Reputation: 21

How to match dataset with formats catalog in sas

I've downloaded a sas dataset and a format catalog that goes with it. This is probably super basic but I can't seem to set up the libraries so that I can make use of the formats, and I can't open the dataset unless I use the NOFMTERR option. They are both in the same windows folder. Please help.

Upvotes: 2

Views: 739

Answers (2)

Joe
Joe

Reputation: 63424

For users of 9.1.3, you can directly alter the fmtsearch option. Here's a method of doing so most similar to @mjsqu's code above (which preserves the already-existing format options) and appends to the end.

* 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));

Of course, this will re-append the value multiple times if you run this multiple times; that's not harmful, but might look odd. You could do some additional checking to see if it is already in the string and not re-add if it is.

Upvotes: 1

mjsqu
mjsqu

Reputation: 5452

The following code should explain how to add a library (in this case the library mylib) to the FMTSEARCH option which dictates which libraries are searched for SAS formats:

/* 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));

Just point SAS to the library where your format catalog is, and this should resolve the format errors and allow you to display the formatted data.

Upvotes: 2

Related Questions