BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Melk
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

11 REPLIES 11
Melk
Lapis Lazuli | Level 10

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?

PeterClemmensen
Tourmaline | Level 20

Try using PROC IMPORT instead of a simple data step

Melk
Lapis Lazuli | Level 10

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)?

ballardw
Super User

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.

Melk
Lapis Lazuli | Level 10

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.

ballardw
Super User

@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.

Melk
Lapis Lazuli | Level 10

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.

Melk
Lapis Lazuli | Level 10

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?

ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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