DATA Step, Macro, Functions and more

Permanent formats not loading using the set statement

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

Permanent formats not loading using the set statement

I have an excel data file on a folder on my computer and a sas code that generates and saves a format for that dataset - I saved the sas dataset with formats and the permanent formats to the same location on my computer.

 

When I go to import that sas data set using a libname and a set statement, I get an error that the formats "were not found or could not be loaded." All of the formats, excel, and sas dataset is saved to the same folder. I am not sure what I am doing wrong?

 

I am using SAS 9.4.


Accepted Solutions
Solution
‎06-05-2017 03:30 PM
Super User
Posts: 11,343

Re: Permanent formats not loading using the set statement

Is the library that you created the formats in, LIB from your code, part of your current FMTSEARCH path?

 

This code will show your current setting for FMTSEARCH (at least in Base SAS);

 

proc options option=fmtsearch;run;

 

The result will look like

 

FMTSEARCH=(WORK LIB); if the format library you created is in the path.

If not you need to execute

 

options fmtsearch=(WORK LIB); or an appropriate version with append or insert.

View solution in original post


All Replies
PROC Star
Posts: 734

Re: Permanent formats not loading using the set statement

Can you show us your code?

Frequent Contributor
Posts: 76

Re: Permanent formats not loading using the set statement

It is just a set statement with reference to the libname. I think the problem is why isnt it reading in the formats - they are saved under the same libname?

PROC Star
Posts: 734

Re: Permanent formats not loading using the set statement

[ Edited ]

Try using PROC IMPORT instead of a simple data step

Super User
Posts: 7,762

Re: Permanent formats not loading using the set statement

There is code that creates the format(s), and there is code that tries to use them. We need to see both to be able to help.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 76

Re: Permanent formats not loading using the set statement

[ Edited ]
Posted in reply to KurtBremser

proc format library=work.formats cntlout = lib.formats;
run;
proc format library=lib.formats cntlin=lib.formats;
run;

 

**

 

I also saved the dataset to the same lib. When I close and open SAS and run a code to just set the sas dataset, the formats dont load automatically (I thought they were supposed to)?

Solution
‎06-05-2017 03:30 PM
Super User
Posts: 11,343

Re: Permanent formats not loading using the set statement

Is the library that you created the formats in, LIB from your code, part of your current FMTSEARCH path?

 

This code will show your current setting for FMTSEARCH (at least in Base SAS);

 

proc options option=fmtsearch;run;

 

The result will look like

 

FMTSEARCH=(WORK LIB); if the format library you created is in the path.

If not you need to execute

 

options fmtsearch=(WORK LIB); or an appropriate version with append or insert.

Frequent Contributor
Posts: 76

Re: Permanent formats not loading using the set statement

Thanks - my libname was not in the path. This used to work for me as long as I saved the dataset with the formats and used the set statement within the same libnane. Its odd that its not working anymore and I have to specify the format path. Wonder what changed.

Super User
Posts: 11,343

Re: Permanent formats not loading using the set statement


Melk wrote:

Thanks - my libname was not in the path. This used to work for me as long as I saved the dataset with the formats and used the set statement within the same libnane. Its odd that its not working anymore and I have to specify the format path. Wonder what changed.


One of the fun things with perisitent data elements in any environment is how are they kept and changed. You may have set the option at sometime in the past using one of the menus and then run a bit of someone's code that modified options and then when the SAS session closed the options were saved as of the state when closed.

 

I use an autoexec.sas program that executes everytime SAS starts to make sure that some of these items are set just in case as well as library assignments and such.

Frequent Contributor
Posts: 76

Re: Permanent formats not loading using the set statement

Ah interesting. Would be interested in what kinds of steps you find important to run in yout autoexec file if you would not mind sharing.

Frequent Contributor
Posts: 76

Re: Permanent formats not loading using the set statement

Another related question.

 

If I specify some more formats but do not save them, and save that updated dataset, when I open SAS again later do I have to rerun the formats? Is there any way to save a dataset with formats permanently?

Super User
Posts: 11,343

Re: Permanent formats not loading using the set statement

If the formats are in a permanent library AND the FMTSEARCH option references that library AND that library is active for the current session that is all you need. If those three conditions are not met then you need to reexecute the code to create the formats, set the FMTSEARCH option and/or create the library depending which have not been done in the current session. How you get that library active in the session depends on your preferences of using the menus to create a permanent library and set the FMTSEARCH option or code is your choice. Mine as I mentioned has been code in an Autoexec.sas file for more than 20 years.

 

How to tell SAS where that autoexec program file may be varies a bit from installation to installation. The content would look something like:

 

libname Lib "path to the lib location";

 

options fmtsearch = (work lib);

 

 

Formats can be permanently associated with variables in a data step with the FORMAT statement, with Proc Datasets and the Modify statement and some other procedures that create data sets when formats are assigned to variables.

However that is only the bit that tells SAS to use Format XXX. to display variable YYY. The actual format is stored in a special file type called a Catalog in the format you specify when you create the format. There is an option that tells SAS what to do when it encounters one of these format names not currently found: Options fmterr; will treat a not found format as an error and halt processing or Options NoFmtErr allows code to run but will assume a BEST format for numerics and a $ format for character.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 527 views
  • 4 likes
  • 4 in conversation