BookmarkSubscribeRSS Feed
Nietzsche
Lapis Lazuli | Level 10

Hi, I am currently reading chapter 12 of the specialist prep guide on proc format. The example data set they are using is missing and the chapter is confusing.

 

1. first question regarding to storing formats permanently using LIBNAME statement.

Nietzsche_0-1668305362332.png

I am following the above instruction and created a library called "formtlib" for storing the format catalog(s). So after a create some format and the catalog is created in the directory, but the library "formtlib" is still empty? It is not linked to the directory where the catalog is stored? see below

 

Nietzsche_2-1668305637094.pngNietzsche_1-1668305584915.png

 

2. So no matter how many formats I create with the VALUE statement, they will all be store inside the FORMATS catalog in the directory above? Does that mean I will only ever need/see on catalog called FORMATS? And I can not change the catalog name etc?

 

 

 

 

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
5 REPLIES 5
PaigeMiller
Diamond | Level 26

I am following the above instruction and created a library called "formtlib" for storing the format catalog(s). So after a create some format and the catalog is created in the directory, but the library "formtlib" is still empty? It is not linked to the directory where the catalog is stored? see below

I see the same thing. Try using one of the formats. That works for me even when FORMTLIB seems empty, the format in FORMTLIB is used as expected. (Hint — Maxim 4 which says: "If in doubt, do a test run and look at the results." Always good thing to do, and you get faster answers than if you take the time to write a question here and then wait for the answer. There's no real reason why I have to go ahead and try it and tell you the answer when you could try it and get your own answer.)

 

So no matter how many formats I create with the VALUE statement, they will all be store inside the FORMATS catalog in the directory above?

Yes

 

Does that mean I will only ever need/see on catalog called FORMATS? And I can not change the catalog name etc?

 

I don't know why you would need a different name for your formats in WORK, but you can certainly use a different name if you want. Maybe there are rare cases where you need two or more format libraries under WORK that I have never run into, but for beginners, don't make your life difficult, accept the simple solution of using the default name.

--
Paige Miller
Quentin
Super User

Re:

I am following the above instruction and created a library called "formtlib" for storing the format catalog(s). So after I create some format and the catalog is created in the directory, but the library "formtlib" is still empty? 

It looks like based on the library viewer (in Studio?) you are saying that the library is empty.  It's possible, based on what you and @PaigeMiller wrote, that the library viewer is designed to show data sets, but not format catalogs.  If you go to C:\Users\Student1\formats\lib using windows explorer (or whatever OS tool), can you see formats.sas7bcat there?

 

Re:

So no matter how many formats I create with the VALUE statement, they will all be store inside the FORMATS catalog in the directory above? Does that mean I will only ever need/see one catalog called FORMATS? And I can not change the catalog name etc?

Yes, when you run PROC FORMAT, all of the formats will be written to one format catalog.  It is possible to specify the name of the format catalog when you create it, but in my experience most people leave it as the default formats.sas7bcat.

 

The below code creates a format catalog quentin.sas7bcat.

 



options dlcreatedir;
libname junk "Q:\junk\fmttest" ;

proc format library=junk.Quentin ;
  value yn 
    0='nope'
    1='yes'
  ;
run ;


*Use widnows DIR command to check what is in the \fmttest folder ;

filename cmd pipe 'dir Q:\junk\fmttest' ;

data pgm; 
 infile cmd lrecl=32727 truncover scanover;
 input dirtext $200.;
 put _infile_ ;
run;

Returns:

1
2    options dlcreatedir;
3    libname junk "Q:\junk\fmttest" ;
NOTE: Libref JUNK was successfully assigned as follows:
      Engine:        V9
      Physical Name: Q:\junk\fmttest
4
5    proc format library=junk.Quentin ;
6      value yn
7        0='nope'
8        1='yes'
9      ;
NOTE: Format YN has been written to JUNK.QUENTIN.
10   run ;


11
12
13   *Use widnows DIR command to check whatis in the \fmttest folder ;
14
15   filename cmd pipe 'dir Q:\junk\fmttest' ;
16
17   data pgm;
18    infile cmd lrecl=32727 truncover scanover;
19    input dirtext $200.;
20    put _infile_ ;
21   run;

NOTE: The infile CMD is:
      Unnamed Pipe Access Device,
      PROCESS=dir Q:\junk\fmttest,RECFM=V,
      LRECL=32727

 Directory of Q:\junk\fmttest

11/13/2022  08:01 AM    <DIR>          .
11/13/2022  08:01 AM    <DIR>          ..
11/13/2022  08:08 AM            17,408 quentin.sas7bcat
               1 File(s)         17,408 bytes
NOTE: 10 records were read from the infile CMD.
      The minimum record length was 0.
      The maximum record length was 55.
NOTE: The data set WORK.PGM has 10 observations and 1 variables.

It's possible the code at the end where I use filename pipe to run the windows DIR command won't work for you.  In many learning editions, there is an option set off to prevent users from using SAS to run operating system commands.  But since you are on Windows, you should just be able to look in the folder using Windows Explorer.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Tom
Super User Tom
Super User

Formats are stored in CATALOGS not DATASETS. The picture on the right is showing the DATASETS in the library.  Unless you ran some other code to create some datasets in that library then it should appear to be empty.  

 

You can use a different member name for the catalog.  But you will need to use a TWO LEVEL name in the LIB= option when using PROC FORMAT to manage the format catalog.  When you use a ONE LEVEL name it is used as the LIBNAME with a a MEMNAME of FORMATS.   Note this is different than the behavior when using one level names to reference datasets where the single level name is assumed to be the MEMNAME and the default WORK libname (or USER libname when defined or if the USER system option is set to another libref then that one is used). 

 

If you want SAS to use the formats then the catalog needs to be added to FMTSEARCH option.  Again in the FMTSEARCH option a one level name is interpreted as the LIBNAME and the default memname of FORMATS is used.  If you want to reference a catalog with a different name then use a TWO LEVEL name.

ballardw
Super User

I would consider this statement as very erroneous:

" So after a create some format and the catalog is created in the directory, but the library "formtlib" is still empty?"

 

It is obviously "not empty" if there is a catalog there. What do you expect to find? The library contains the catalog with the formats. Until you do something to place other things there that is all that would be in the library.

 

One of the OPTIONS on your Proc Format, LIBRARY statement

From the documenation

the LIBRARY= option.

LIBRARY=libref<.catalog>

specifies a SAS library or catalog that contains the informats or formats that you are creating in the PROC FORMAT step.

 

So if you have a library named ABC and want to create a format catalog with the name of PDQ the syntax would be

Proc format library=ABC.PDQ;
<other proc format statements>
run;

Just like any other SAS data set or catalog you can even change the name afterwards. One of the differences is if you provide a non-standard name for the format catalog then when you specify the FMTSEARCH path to use the formats you must also specify the catalog as well as the library. Until the library and format catalog is in the format search path you won't be able to use the formats.

 

 

ghosh
Barite | Level 11

The following example shows how to list the formats in your format library and display their contents:

libname FMT '~/dat/';

proc format LIB=FMT.FORMATS;

	value $loc  'e'='en_US'  'f'='fr_CA';
	value $lang 'e'='EN'  'f'='FR';
	VALUE  sexf  0='Other' 1='Male' 2='Female';
run;
Title "Format Library Index";
proc catalog c = FMT.FORMATS;
	contents stat;
run;
Title "Format Library Contents";
proc format
	library = FMT.formats fmtlib;
run;
Title '';

ghosh_0-1668366300161.png

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 516 views
  • 0 likes
  • 6 in conversation