4. CA MICS Facilities › 4.5 User-defined Informats and Formats › 4.5.1 Creating Complex-level Catalog Entries
4.5.1 Creating Complex-level Catalog Entries
The USERFMTC job is available to update the USERFMT1 and
USERFMT2 catalogs in sharedprefix.MICS.MCOLIB. The USERFMTC
job is automatically generated in sharedprefix.MICS.CNTL.
The input to this catalog update job is the following members
of sharedprefix.MICS.USER.SOURCE:
USERFMT1 - Adds and updates entries in catalog USERFMT1
USERFMT2 - Adds and updates entries in catalog USERFMT2
The only code that needs to be entered in these members is
the INVALUE, VALUE, and/or PICTURE statements necessary to
generate your formats. Please refer to the SAS Procedures
Guide for complete syntax rules on coding these input
statements to PROC FORMAT. Any number of these statements
can be coded in each member. All formats defined in this
member will be updated each time the USERFMTC job is
executed. An invocation of PROC FORMAT with output to the
appropriate catalog is automatically invoked and need not be
coded in the input member.
If you have need to perform more complicated processing, such
as a DATA step that reads an external file and then generates
a format, that code can either be coded in these members or
%INCLUDEd from standard CA MICS libraries or private data
sets. The only requirement is that you code your PROC FORMAT
invocation statements in the following format:
PROC FORMAT LIBRARY=MCOLIB.USERFMTn;
...INVALUE, VALUE, and/or PICTURE statements...
RUN;
Examples of various input methods that can be used in these
members follow.
Example 1--Coding INVALUE, VALUE, and PICTURE statements to
be processed by PROC FORMAT.
INVALUE CHECK
'1'-'4'=_SAME_
'99' =.
OTHER =_ERROR_;
PICTURE DAYS
01-31='99'
OTHER='99 - Illegal day value';
VALUE ABC
1='A'
2='B'
3='C';
VALUE $TAPES
'0300'-'032F'='TAPE'
'0400'-'043F'='CART'
'0800'-'08FF'='SILO'
OTHER='????';
Example 2--Reading a sequential file's values for use in a
table search.
The following code can be used to input a sequential file
containing a list of valid codes for use in a table search
for permissible values of a SAS variable. The format will be
saved in the USERFMT2 catalog in sharedprefix.MICS.MCOLIB.
This format is referenced later in this section to select
only observations that do not have an ACCTNO1 value in this
format.
In this example, the SAS code inputs the first non-blank
field in each record as the table look-up entry. If the
first non-blank field in each record is not used as the
look-up value, the INPUT statement must be changed to
properly input the desired values. The SAS code shown below
creates a format called $USRIDS in the USERFMT2 catalog in
sharedprefix.MICS.MCOLIB. You may want to change the name of
the format that is created. The format name must begin with
a "$" if you use a SAS character variable to do the table
look-up in the DATA step PUT function. If a numeric variable
is used in the PUT function, the FORMAT name must begin with
a letter.
/* ALLOCATE THE INPUT DATA SET */
FILENAME INPUT 'your.input.dataset.name' DISP=SHR;
DATA _NULL_;
LENGTH TEMP1 $16; /* MAX LENGTH OF LOOK-UP VALUE */
INFILE INPUT END=EOF; /* INPUT SEQUENTIAL FILE */
FILE FT15F001; /* TEMP WORK FILE IN MICSDM PROC */
PUT "PROC FORMAT LIBRARY=MCOLIB.USERFMT2;" /
"VALUE $USRIDS ";
DO UNTIL(EOF);
/* LOOK-UP VALUES ARE IN THE FIRST NON-BLANK COLUMN */
INPUT TEMP1 $ ;
PUT "'" TEMP1 "' = '1'";
END;
PUT "OTHER = '0';";
STOP;
RUN;
%INCLUDE FT15F001; /* INC. THE GENERATED PROC FORMAT */
RUN;
FILENAME INPUT CLEAR; /* FREE THE INPUT DATA SET */
An alternate method to perform the same process is to use the
CNTLIN option of PROC FORMAT. Notice that the format name
variable FMTNAME does not have the $ in the retained value.
The fact that this is a character format is defined by
setting the format type variable, TYPE, to C. The format is
still referenced as $USRIDS in a PUT statement.
/* ALLOCATE THE INPUT DATA SET */
FILENAME INPUT 'your.input.dataset.name' DISP=SHR;
DATA WORK.CNTLIN;
LENGTH START END $16; /* MAX LENGTH OF LOOK-UP VALUE */
RETAIN FMTNAME 'USRIDS' /* NAME OF FORMAT TO BE GEN'D */
TYPE 'C' /* THIS IS A CHARACTER FORMAT */
HLO ' ' /* FOR USE WITH OTHER= OPTIONS */
LABEL '1';
INFILE INPUT END=EOF; /* INPUT SEQUENTIAL FILE */
DO UNTIL(EOF);
/* LOOK-UP VALUES ARE IN THE FIRST NON-BLANK COLUMN */
INPUT START $ ;
END=START; /* START/END OF RANGE ARE SAME */
OUTPUT;
END;
START='**OTHER**'; /* GENERATE AN OTHER= VALUE */
END=START;
HLO='O';
LABEL='0';
OUTPUT;
STOP;
RUN;
/* GENERATE THE FORMAT */
PROC FORMAT CNTLIN=WORK.CNTLIN
LIBRARY=MCOLIB.USERFMT2 PRINT;
RUN;
FILENAME INPUT CLEAR; /* FREE THE INPUT DATA SET */
If the code in the above example were stored in a private
partitioned data set, it could be added to the USERFMTC
update process as follows:
%INCLUDE 'your.private.pds(member)';
SAS will dynamically allocate, read, and free the data set
for you.
If the code in the above example was stored in another member
of sharedprefix.MICS.USER.SOURCE, it could be added to the
USERFMTC update process as follows:
%INCLUDE USOURCE(member);
A sample SAS DATA step that uses the format $USRIDS to subset
a SAS file by selecting observations that have certain
ACCTNO1 values is illustrated in the sample SAS code that
follows:
//MICS EXEC MICSSHRP
//SYSIN DD DATA,DLM=ZZ
/* SAVE ALL OBS. THAT CONTAIN INVALID ACCTNO1 VALUES */
DATA REJECTS (KEEP=ACCTNO1 ACCTNO2 JOB RDRTS);
SET &BATX..BATJOB01;
IF PUT(ACCTNO1,$USRIDS.) = 0 THEN OUTPUT;
RUN;
/* PRINT REJECT OUTPUT REPORT */
PROC PRINT DATA=REJECTS; BY ACCTNO1;
ID JOB; VAR ACCTNO1 ACCTNO2 RDRTS;
TITLE " REJECT LISTING FROM BATJOB FILE ";
RUN;
ZZ
The logic in the sample DATA step above will output any
observation that does not have one of the user identification
(ACCTNO1) values that is contained in the SAS format $USRIDS.
This technique can be used to identify and print exceptions
or rejects.