Write and run SAS programs in your web browser

Cannot load custom formats using options=fmtsearch(libref)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Cannot load custom formats using options=fmtsearch(libref)

I am hoping someone might be able to shed some light on why options=fmtsearch(libref) does not work, but % include "filepath" does. I wonder what different syntax might be needed in SAS Studio in the the options statemement?

Below the code that does not work:

libname libref "/folders/myfolders/thefoldername";
options fmtsearch=(libref);
data mydata;
set thefoldername.mydata;
run;
proc sgplot data=mydata;
 title1 'Scatterplot of v1 vs v2';
 title2 'All Participants'; scatter x=v1 y=v2;
 xaxis values=(50 to 80 by 10);
 run; title;

the plot works fine, the correct number of observations are read in but the log show the formats are not loaded:

 

NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format SES was not found or could not be loaded.
etc
 
As I mentioned earlier, using %include "filepath" works fine - formats are loaded.
 
I spent hours pouring over the boards and searching on the internet but to no avail. Could anyone help?
 
Thanks!

Accepted Solutions
Solution
‎04-26-2017 04:38 AM
Super User
Posts: 7,405

Re: Cannot load custom formats using options=fmtsearch(libref)

Check the include files to see in which library the formats are created. Big chance that it is work, so your fmtsearch would be useless.

Keep in mind that including the .sas files executes the proc format and creates the formats on the spot, while fmtsearch only works for formats that have already been created with the format procedure.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 3,233

Re: Cannot load custom formats using options=fmtsearch(libref)

I suspect there may be some misunderstanding here. %include is for including and running SAS code, which I'm guessing contains the code that creates the SAS formats.

 

For FMTSEARCH to work it needs to point to the SAS library where the SAS FORMAT catalog is created. By default, this will be the WORK library unless you specify otherwise. What you could try is this:

libname libref "/folders/myfolders/thefoldername";

proc format library = libref;
  * put your format code here;
run;
Super User
Posts: 19,052

Re: Cannot load custom formats using options=fmtsearch(libref)

You may want to explore using %include within your autoexec. Giventthat catalogs don't transfer systems, ie from Unix to Windows or 32bit to 64 bit is also an issue, it may be easier to stick with loading formats either as needed or at startup.

Occasional Contributor
Posts: 12

Re: Cannot load custom formats using options=fmtsearch(libref)

Hello Reeza

 

Thanks for your reply - although I don't have the technical knowledge under my belt yet to understand what you mean with

 

"catalogs don't transfer systems"?

 

 

Super User
Posts: 7,405

Re: Cannot load custom formats using options=fmtsearch(libref)


gabyelle wrote:

Hello Reeza

 

Thanks for your reply - although I don't have the technical knowledge under my belt yet to understand what you mean with

 

"catalogs don't transfer systems"?

 

 


@Reeza means that SAS catalogs are version and operating system specific. A libref.formats catalog created with version X may not be usable with version Y. SAS programs, OTOH, can easily be used in different SAS versions and on different platforms.

proc format library=libref;
......
run;

options fmtsearch=(libref);

is totally portable, just the libname statement needs to be adapted.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,359

Re: Cannot load custom formats using options=fmtsearch(libref)

Just a possibility ...

 

When you don't specify the name of the catalog to look in to locate formats, it's assumed to be named formats.  So the catalog name that's being searched is libref.formats.  It's possible that the formats are actually saved under a different catalog name within that same libref.  You would have to specify the two-part name within the FMTSEARCH option, for example, libref.myformats or whatever the name actually is.

Solution
‎04-26-2017 04:38 AM
Super User
Posts: 7,405

Re: Cannot load custom formats using options=fmtsearch(libref)

Check the include files to see in which library the formats are created. Big chance that it is work, so your fmtsearch would be useless.

Keep in mind that including the .sas files executes the proc format and creates the formats on the spot, while fmtsearch only works for formats that have already been created with the format procedure.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 12

Re: Cannot load custom formats using options=fmtsearch(libref)

[ Edited ]

Thanks very much Kurt - you have clarified a lot and I got to the bottom of it thanks to your hints - the formats weren't being loaded because the statement library=... after proc format was missing in the format file I had been given.

I also found out that there are two catalogs in SAS Studio - not just formats.sas7cat but also format.sas7cat - I can set the code to refer to either, by using library=libref.format or libref.formats - as long as I keep the reference consistent when I call the formats in the options fmtsearch=(libref.format(s)). 

As AmyP pointed out in another post on SAS catalogs, you can't actually see what is in the catalog directly (I tried the code snippets but cannot make much sense of the output as I can't open the individual catalogs).

 

As an aside, a difference I noticed when comparing logs produced after running %include and options fmtsearch=( ) is that the log doesn't confim the formats are loaded in the latter, but they appear to actually have loaded as the data displays the correct value labels.

 

I wonder why?

 

PS I also read your Maxims - very useful reading even for a beginner like me!

Super User
Posts: 7,405

Re: Cannot load custom formats using options=fmtsearch(libref)

If SAS is given only a library name in fmtsearch, it will look for formats.sas7bcat in that library. But you can use any name for a formats catalog when you specify a two-level name (eg libref.format, note the missing "s") in fmtsearch.

 

The Maxims will be expanded in the future, so take a look every now and then. Suggestions are also welcome.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 12

Re: Cannot load custom formats using options=fmtsearch(libref)

OK - got it Kurt - thanks again!

☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 197 views
  • 3 likes
  • 5 in conversation