BookmarkSubscribeRSS Feed
LOLO
Obsidian | Level 7

I have two different format catalogs which I need to use depending on how the client needs the output displayed.

 

%let fmt1=formats1 ;

%let fmt2=formats2 ;

libname fmts  "\\path\formats" ;

 

options fmtsearch=(fmts.formats2 fmts.formats2 work library) ;

 

Each catalog has about 100 different formats, some of them the same and some different.

 

proc print data =mydata ; var var1-var3 ; run ;

 

So I want the data file to look into formats2 to apply the formats. Formats1 was created first and I have applied these formats to 'mydata' in a previous program. Now I want SAS to apply formats2 instead of formats1. I did what SAS said and put the order into the fmtsearch option, but I still get results showing the formats1 formats. What am I doing wrong? I'm running this in Batch.

 

Thanks!

 

Lorena

 

 

 

10 REPLIES 10
SuryaKiran
Meteorite | Level 14

Your LIBNAME is invalid. Remove "="

 

libname fmts  "\\path\formats" ;

Thanks,
Suryakiran
LOLO
Obsidian | Level 7

ha was a typo... I have it written correctly in the program. Sorry!

SuryaKiran
Meteorite | Level 14

This shouldn't happen, are you sure you don't have WORK or LIBRARY before user-defined catalog search libref and the format your searching exists. 

Thanks,
Suryakiran
ballardw
Super User

The format search path creates an order of search for formats. If the requested format is not found in the first format catalog listen then it goes the next and so on until found (or not).

 

Your problem looks like the affective options statement is this one, not the one shows.

options fmtsearch=(fmts.formats1 fmts.formats2 work library) ;

 

I would verify that both of the catalogs exist at the time the code runs AND that the expected formats are in expected catalogs.

LOLO
Obsidian | Level 7

Right...it is very confusing because I feel like it should work too. The format I want is in formats2. In a previous program I had called formats1 and applied those formats. I have a question. Would it make more sense to use a datasets statement and remove all formats and then do the frmtsearch option? It makes no sense to me.

LOLO
Obsidian | Level 7

More information. I inherited a data file that had formats (formats1). How do I replace those formats with formats2? Maybe this is why it doesn't work, it keeps seeing the old formats from formats1?

ballardw
Super User

Try adding this line of code immediately before the step where you get the misbehaving format usage:

Proc options option=fmtsearch;run;

That will write the actual in effect search path to the log.

 

 

Also you may want to run this code:

title "In FMTS.FORMATS1";
proc format library=FMTS.FORMATS1 fmtlib;  
;
run;TITLE;

title "In FMTS.FORMATS2";
proc format library=FMTS.FORMATS2 fmtlib;  
;
run;TITLE;

to get human readable text of the contents to verify which catalog has which catalog has which formats and the assignments. Perhaps the issue is more subtle than the search order but that the format does not exist or is the wrong type in the Formats2 catalog.

 

Tom
Super User Tom
Super User

More data will help us to understand what might be the problem. A small program that reproduces the problem would be even better.

 

What is the name of the variable that has a format attached to it?  What format is attached to it?  Does that format exist in only one of the format catalogs? Or both? Or neither?  Are you sure that the format is the proper type for the variable that it is being used with?

 

Why do you need to keep both catalogs in the search path?

 

Are you redefining/changing your librefs?  Are you sure that the LIBNAME statement ran without errors?

 

Someone showed me this undocumented function that a SAS based data explorer tool was using. 

You might try adding this step after changing the FMTSEARCH path.

data _null_;
   call fmtdel();
run;
ChrisNZ
Tourmaline | Level 20

Something is at play that you don't show.

Start with this working example, and slowly add your environment and data until you identify the breaking point.

 

options dlcreatedir;
libname T1 "%sysfunc(pathname(WORK))\T1" ; 
libname T2 "%sysfunc(pathname(WORK))\T2" ; 
               
proc format lib=T1; value $test 'A'='t1'; run;
proc format lib=T2; value $test 'A'='t2'; run;
                        
options fmtsearch=(T1.FORMATS T2.FORMATS WORK);
data _null_; A='A'; put A= $test.; run;

options fmtsearch=(T2.FORMATS T1.FORMATS WORK);
data _null_; A='A'; put A= $test.; run;
A=t1
A=t2

 

Ksharp
Super User

options fmtsearch=(fmts) ;

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
  • 10 replies
  • 3136 views
  • 0 likes
  • 6 in conversation