SAS Value Labels
Previous Topic  Next Topic 

Stat/Transfer supports the import and export of SAS value labels. 


Reading SAS Value Labels

SAS, unlike other systems, stores value labels as custom "formats," in a separate "catalog" file.    Stat/Transfer can read SAS user-defined formats (value labels) directly from 64 or 32 bit Windows catalog files.  This is the simplest option for those who are using Windows SAS.


In addition, Stat/Transfer can read SAS formats that are stored in several other formats.  These may be more convenient if your data are coming from another SAS platform, or you simply have no control over the way the data are produced and delivered.


Stat/Transfer can read formats from catalogs stored in CPORT libraries


Stat/Transfer can read formats from an exported catalog produced by SAS using the 'cntrlout=' option of PROC FORMAT.  (See "Creating a File with the PROC FORMAT Statement" below.)  The files produced in this way can be stored in:





Setting the Appropriate Options with the User Interface

You can choose whether and how formats are to be read by using the Reading SAS Value Labels options of the Options dialog box.


Do not read formats

Check this option, which is the default, if no formats will be read.


Read directly from a catalog file

Choose this option if you have a Windows SAS catalog file containing formats and wish to read them.


If this option is checked, the entry '%ipath%/catalog.sas7bcat' will automatically appear on the SAS catalog name line.  This instructs Stat/Transfer to look for a file named FORMATS.SAS7BCAT, in the same directory as your data file.  You can change the path if your file is in a different location.


Read from a catalog in CPORT library

Check this option if you have your formats in a CPORT catalog.


If this option is checked, the entry '%ipath%/%iname%.stc' will automatically appear on the CPORT library name line.  This instructs Stat/Transfer to look for a file with the name (with extension .stc) and directory of your input file, since you will most probably be reading your formats from the same file as the data.  If you are reading formats and data from separate files, then you can give the name of the file on this line. You can type in a complete file specification or you can use the macros below as part of the file specification.


%ipath% The path, including the directory, of the input file

%iname% The name, without the extension, of the input file

%iext% The extension, without the dot, of the input file


If your formats are in a member with the default name formats, you need not specify anything more.  If not, uncheck the Use default catalog name box and press the Read Library button.  You will then be able to select the member that contains your formats.


Read a SAS datafile

Choose this option if you wish to read formats from a SAS datafile produced by SAS using PROC FORMAT.  When this option is checked, you must have both the SAS input file and a separate file created by SAS that contains the formats. By default, Stat/Transfer will look in the same directory as the input file for a file named sas_fmts.ext, where .ext is the extension of your input file.  This is the name that the file will have if you have created it by the procedure below.


If you wish to have Stat/Transfer look for a file located somewhere else or with a different name, you can change it in the SAS dataset name box.  You can type in a complete file specification or you can use the macros given above as part of the file specification.


Read from a dataset in a CPORT library

Choose this option if you have your formats in a dataset in a CPORT library produced by PROC FORMAT.


If this option is checked, the entry '%ipath%/%iname%.stc' will automatically appear on the CPORT library name line.  This instructs Stat/Transfer to look for a file with the name (with extension .stc) and directory of your input file, since you will most probably be reading your formats from the same file as the data.  If you are reading formats and data from separate files, then you can give the name of the file on this line. You can type in a complete file specification or you can use the macros above as part of the file specification.


If your formats are in a dataset with the default name sas_fmts, you need not specify anything more.  If not, uncheck the Use default catalog name box and press the Read Library button.  You will then be able to select the dataset that contains your formats.


Read from a SAS Transport file

Choose this option if you have your formats in a dataset in a SAS Transport file produced by PROC FORMAT.


If this option is checked, the entry '%ipath%/%iname%.tpt' will automatically appear on the Transport library name line.  This instructs Stat/Transfer to look for a file with the name (with extension .tpt) and directory of your input file, since you will most probably be reading your formats from the same file as the data.  If you are reading formats and data from separate files, then you can give the name of the file on this line. You can type in a complete file specification or you can use the macros above as part of the file specification.


If your formats are in a subfile with the default name sas_fmts, you need not specify anything more.  If not, uncheck the Use default member name box and press the Read Library button.  You will then be able to select the subfile that contains your formats.



Setting the Appropriate Options with the Command Processor Interface

SET commands are used to choose whether and how formats are to be read.  See the section SAS Value Labels-Reading in the Available Options section.



Creating a File with the PROC FORMAT Statement

To create the new file for Stat/Transfer to use for reading your SAS value labels, you will need to go into SAS and run the following small program:


libname mylib 'path';

proc format library = mylib

cntlout = mylib.sas_fmts;

run;


where 'path' is the directory that contains your input data file.


This procedure creates a SAS file in the directory 'path' that has the format information for each SAS data file.  In this case, the file will have the name sas_fmts.ext, where .ext is the extension of the input SAS file, and it will be found in the same directory as the input file.


To put your formats in CPORT library, use PROC FORMAT after the above procedure.


To create a format library in a Transport file, use the same procedure as above but reference the XPORT engine in the output 'libname' statement.



Transferring Value Labels with Data

When you carry out a transfer with a SAS data file as input, Stat/Transfer will check to see if you have checked the option Read formats directly from a catalog file.  If so, the value labels will be transferred automatically from the catalog file named in the Filename box.


If you check any of the other options, Stat/Transfer will look for the file that you have specified and the formats will be transferred automatically.



Restrictions on Importing Value Labels

SAS catalog files not only support conventional value labels (the one-to-one mapping of a string to a single number), but also the mapping of a range of numeric values to a single string (for example, zip code mapped to state).


Because this latter form has no analog in any of the packages supported by Stat/Transfer, only conventional one-to-one value labels are imported from SAS.



Options controlling how labels are processed

You can control how Stat/Transfer will behave if all does not go smoothly.


Continue if the format file is not found

By default,  processing will stop if a file containing the formats is not found.  Change this behavior by unchecking this option.


Continue is there is an error processing formats

By default,  processing will stop if there is an error reading the format file or if no tags in the dataset are matched to formats in the file.  By checking this option, you tell Stat/Transfer to continue processing even if there is an error processing the formats.


Writing SAS Value Labels

The separate catalog file in which SAS stores value labels, besides being undocumented, can be shared among several SAS data sets.  This makes it problematic to update a SAS catalog file using an external program.  When writing value labels for SAS data files, rather than update the catalog file directly, Stat/Transfer creates a SAS program that you can run in order to have SAS update its catalog file.


Setting the Appropriate Options

You will first need to check the appropriate box in the SAS Value Labels - Writing section of the Options dialog box, Write a Proc Format program, to enable the writing of SAS labels.  Below this option is the Filename line.  If you leave the default name, the program file that you are going to create will have the name of the output SAS data file, with the extension .sas, outfilename.sas, and will be placed in the same directory as the output SAS data file.  See Writing SAS Value Labels for details.


Transferring Value Labels with Data

When you carry out a transfer with a SAS data file as output, Stat/Transfer will check to see if you have checked the option Write a Proc Format program.  During the transfer, it will then write a SAS PROC program file with the name taken from the Filename line.  In this case, assuming that you have used the default name and directory, it will create a program file named outfilename.sas in the same directory as the output SAS data file.


For example, if you write a SAS data file called out.sas7bdat, the PROC program  will be in the same directory as the output file and will be named OUT.SAS.


The program file has the PROC FORMAT and MODIFY statements necessary to create the SAS catalog file.  Once the program file has been created, you can run it in SAS.