Examples: CATALOG Procedure


Example 1: Copying, Deleting, and Moving Catalog Entries from Multiple Catalogs

Procedure features:

  • PROC CATALOG statement:

    • CATALOG= argument

  • COPY statement options:

    • IN=

    • MOVE

    • NOEDIT

  • DELETE statement options:

    • ENTRYTYPE= or ET=

  • EXCLUDE statement options:

    • ENTRYTYPE= or ET=

    • (ENTRYTYPE=) or (ET=)

  • QUIT statement

  • RUN statement

  • SELECT statement options:

    • ENTRYTYPE= or ET=

This example

  • copies entries by excluding a few entries

  • copies entries by specifying a few entries

  • protects entries from being edited

  • moves entries

  • deletes entries

  • processes entries from multiple catalogs

  • processes entries in multiple run groups.

Input Catalogs

The SAS catalog PERM.SAMPLE contains the following entries:

 DEFAULT      FORM         Default form for printing  FSLETTER     FORM         Standard form for letters (HP Laserjet)  LOAN         FRAME        Loan analysis application  LOAN         HELP         Information about the application  BUILD        KEYS         Function Key Definitions  LOAN         KEYS         Custom key definitions for application  CREDIT       LOG          credit application log  TEST1        LOG          Inventory program  TEST2        LOG          Inventory program  TEST3        LOG          Inventory program  LOAN         PMENU        Custom menu definitions for applicaticm  CREDIT       PROGRAM      credit application pgm  TEST1        PROGRAM      testing budget applic.  TEST2        PROGRAM      testing budget applic.  TEST3        PROGRAM      testing budget applic.  LOAN         SCL          SCL code for loan analysis application  PASSIST      SLIST        User profile  PRTINFO      KPRINTER     Printing Parameters 

The SAS catalog PERM.FORMATS contains the following entries:

 REVENUE      FORMAT      FORMAT:MAXLEN=16,16,12  DEPT         FORMATC     FORMAT:MAXLEN=1,1,14 

Program

Set the SAS system options. Write the source code to the log by specifying the SOURCE SAS system option.

 options nodate pageno=1 linesize=80 pagesize=60 source; 

Assign a library reference to a SAS data library. The LIBNAME statement assigns the libref PERM to the SAS data library that contains a permanent SAS catalog.

 libname perm '  SAS-data-library  '; 

Delete two entries from the PERM.SAMPLE catalog.

 proc catalog cat=perm.sample;     delete credit.program credit.log;  run; 

Copy all entries in the PERM.SAMPLE catalog to the WORK.TCATALL catalog.

 copy out=tcatall;  run; 

Copy everything except three LOG entries and PASSIST.SLIST from PERM.SAMPLE to WORK.TESTCAT. The EXCLUDE statement specifies which entries not to copy. ET= specifies a default type. (ET=) specifies an exception to the default type.

 copy out=testcat;        exclude test1 test2 test3 passist (et=slist) / et=log;  run; 

Move three LOG entries from PERM.SAMPLE to WORK.LOGCAT. The SELECT statement specifies which entries to move. ET= restricts processing to LOG entries.

 copy out=logcat move;        select test1 test2 test3 / et=log;  run; 

Copy five SAS/AF software entries from PERM.SAMPLE to PERM.FINANCE. The NOEDIT option protects these entries in PERM.FINANCE from further editing with PROC BUILD.

 copy out=perm.finance noedit;        select loan.frame loan.help loan.keys loan.pmenu;  run; 

Copy two formats from PERM.FORMATS to PERM.FINANCE. The IN= option enables you to copy from a different catalog than the one specified in the PROC CATALOG statement. Note the entry types for numeric and character formats: REVENUE.FORMAT is a numeric format and DEPT.FORMATC is a character format. The COPY and SELECT statements execute before the QUIT statement ends the PROC CATALOG step.

 copy in=perm.formats out=perm.finance;        select revenue.format dept.formatc;  quit; 

Log

 1    libname perm  'SAS-data-library'  ;  NOTE: Directory for library PERM contains files of mixed engine types.  NOTE: Libref PERM was successfully assigned as follows:        Engine:        V9        Physical Name:  'SAS-data-library'  2    options nodate pageno=1 linesize=80 pagesize=60 source;  3   proc catalog cat=perm.sample;  4      delete credit.program credit.log;  5   run;  NOTE: Deleting entry CREDIT.PROGRAM in catalog PERM.SAMPLE.  NOTE: Deleting entry CREDIT.LOG in catalog PERM.SAMPLE.  6      copy out=tcatall;  7   run;  NOTE: Copying entry DEFAULT.FORM from catalog PERM.SAMPLE to catalog        WORK.TCATALL.  NOTE: Copying entry FSLETTER.FORM from catalog PERM.SAMPLE to catalog        WORK.TCATALL.  NOTE: Copying entry LOAN.FRAME from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry LOAN.HELP from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry BUILD.KEYS from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry LOAN.KEYS from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry TEST1.LOG from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry TEST2.LOG from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry TEST3.LOG from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry LOAN.PMENU from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry TEST1.PROGRAM from catalog PERM.SAMPLE to catalog        WORK.TCATALL.  NOTE: Copying entry TEST2.PROGRAM from catalog PERM.SAMPLE to catalog        WORK.TCATALL.  NOTE: Copying entry TEST3.PROGRAM from catalog PERM.SAMPLE to catalog        WORK.TCATALL.  NOTE: Copying entry LOAN.SCL from catalog PERM.SAMPLE to catalog WORK.TCATALL.  NOTE: Copying entry PASSIST.SLIST from catalog PERM.SAMPLE to catalog        WORK.TCATALL.  NOTE: Copying entry PRTINFO.XPRINTER from catalog PERM.SAMPLE to catalog        WORK.TCATALL.  8      copy out=testcat;  9         exclude test1 test2 test3 passist (et=slist) / et=log;  10   run;  NOTE: Copying entry DEFAULT.FORM from catalog PERM.SAMPLE to catalog        WORK.TESTCAT.  NOTE: Copying entry FSLETTER.FORM from catalog PERM.SAMPLE to catalog        WORK.TESTCAT.  NOTE: Copying entry LOAN.FRAME from catalog PERM.SAMPLE to catalog WORK.TESTCAT.  NOTE: Copying entry LOAN.HELP from catalog PERM.SAMPLE to catalog WORK.TESTCAT.  NOTE: Copying entry BUILD.KEYS from catalog PERM.SAMPLE to catalog WORK.TESTCAT.  NOTE: Copying entry LOAN.KEYS from catalog PERM.SAMPLE to catalog WORK.TESTCAT.  NOTE: Copying entry LOAN.PMENU from catalog PERM.SAMPLE to catalog WORK.TESTCAT.  NOTE: Copying entry TEST1.PROGRAM from catalog PERM.SAMPLE to catalog        WORK.TESTCAT.  NOTE: Copying entry TEST2.PROGRAM from catalog PERM.SAMPLE to catalog        WORK.TESTCAT.  NOTE: Copying entry TEST3.PROGRAM from catalog PERM.SAMPLE to catalog        WORK.TESTCAT.  NOTE: Copying entry LOAN.SCL from catalog PERM.SAMPLE to catalog WORK.TESTCAT.  NOTE: Copying entry PRTINFO.XPRINTER from catalog PERM.SAMPLE to catalog        WORK.TESTCAT.  11      copy out=logcat move;  12         select test1 test2 test3 / et=log;  13   run;  NOTE: Moving entry TEST1.LOG from catalog PERM.SAMPLE to catalog WORK.LOGCAT.  NOTE: Moving entry TEST2.LOG from catalog PERM.SAMPLE to catalog WORK.LOGCAT.  NOTE: Moving entry TEST3.LOG from catalog PERM.SAMPLE to catalog WORK.LOGCAT.  14      copy out=perm.finance noedit;  15         select loan.frame loan.help loan.keys loan.pmenu;  16   run;  NOTE: Copying entry LOAN.FRAME from catalog PERM.SAMPLE to catalog PERM.FINANCE.  NOTE: Copying entry LOAN.HELP from catalog PERM.SAMPLE to catalog PERM.FINANCE.  NOTE: Copying entry LOAN.KEYS from catalog PERM.SAMPLE to catalog PERM.FINANCE.  NOTE: Copying entry LOAN.PMENU from catalog PERM.SAMPLE to catalog PERM.FINANCE.  17      copy in=perm.formats out=perm.finance;  18         select revenue.format dept.formatc;  19   quit;  NOTE: Copying entry REVENUE.FORMAT from catalog PERM.FORMATS to catalog        PERM.FINANCE.  NOTE: Copying entry DEPT.FORMATC from catalog PERM.FORMATS to catalog        PERM.FINANCE. 

Example 2: Displaying Contents, Changing Names , and Changing a Description

Procedure features:

  • PROC CATALOG statement

  • CHANGE statement options:

    • (ENTRYTYPE=) or (ET=)

  • CONTENTS statement options:

    • FILE=

  • MODIFY statement

  • RUN statement

  • QUIT statement

This example

  • lists the entries in a catalog and routes the output to a file

  • changes entry names

  • changes entry descriptions

  • processes entries in multiple run groups.

Program

Set the SAS system options. The system option SOURCE writes the source code to the log.

 options nodate pageno=1 linesize=80 pagesize=60 source; 

Assign a library reference. The LIBNAME statement assigns a libref to the SAS data library that contains a permanent SAS catalog.

 libname perm '  SAS-data-library  '; 

List the entries in a catalog and route the output to a file. The CONTENTS statement creates a listing of the contents of the SAS catalog PERM.FINANCE and routes the output to a file.

 proc catalog catalog=perm.finance;     contents;  title1 'Contents of PERM.FINANCE before changes are made';  run; 

Change entry names. The CHANGE statement changes the name of an entry that contains a user-written character format. (ET=) specifies the entry type.

 change dept=deptcode (et=formatc);  run; 

Process entries in multiple run groups. The MODIFY statement changes the description of an entry. The CONTENTS statement creates a listing of the contents of PERM.FINANCE after all the changes have been applied. QUIT ends the procedure.

 modify loan.frame (description='Loan analysis app. - ver1');     contents;  title1 'Contents of PERM.FINANCE after changes are made';  run;  quit; 

Output

 Contents of PERM.FINANCE before changes are made               1                          Contents of Catalog PERM.FINANCE  # Name    Type            Create Date       Modified Date Description  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$  1 REVENUE FORMAT   16OCT1996:13:48:11  16OCT1996:13:48:11 FORMAT:MAXLEN=16,16,12  2 DEPT    FORMATC  30OCT1996:13:40:42  30OCT1996:13:40:42 FORMAT:MAXLEN=1,1,14  3 LOAN    FRAME    30OCT1996:13:40:43  30OCT1996:13:40:43 Loan analysis                                                            application  4 LOAN    HELP     16OCT1996:13:48:10  16OCT1996:13:48:10 Information about                                                            the application  5 LOAN    KEYS     16OCT1996:13:48:10  16OCT1996:13:48:10 Custom key definitions                                                            for application  6 LOAN    PMENU    16OCT1996:13:48:10  16OCT1996:13:48:10 Custom menu                                                            definitions for                                                            application  7 LOAN    SCL      16OCT1996:13:48:10  16OCT1996:13:48:10 SCL code for loan                                                            analysis application 
 Contents of PERM.FINANCE after changes are made                2                          Contents of Catalog PERM.FINANCE  # Name     Type            Create Date       Modified Date Description  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$  1 REVENUE  FORMAT   16OCT1996:13:48:11  16OCT1996:13:48:11 FORMAT:MAXLEN=                                                             16,16,12  2 DEPTCODE FORMATC  30OCT1996:13:40:42  30OCT1996:13:40:42 FORMAT:MAXLEN=1,1,14  3 LOAN     FRAME    30OCT1996:13:40:43  11FEB2002:13:20:50 Loan analysis                                                             app. - ver1  4 LOAN     HELP     16OCT1996:13:48:10  16OCT1996:13:48:10 Information about                                                             the application  5 LOAN     KEYS     16OCT1996:13:48:10  16OCT1996:13:48:10 Custom key                                                             definitions for                                                             application  6 LOAN     PMENU    16OCT1996:13:48:10  16OCT1996:13:48:10 Custom menu                                                             definitions for                                                             application  7 LOAN     SCL      16OCT1996:13:48:10  16OCT1996:13:48:10 SCL code for loan                                                             analysis application 

Example 3: Using the FORCE Option with the KILL Option

Procedure features:

  • PROC CATALOG statement:

    • CATALOG= argument

    • KILL option

    • FORCE option

  • QUIT statement

  • RUN statement

This example

  • creates a resource environment

  • tries to delete all catalog entries by using the KILL option but receives an error

  • specifies the FORCE option to successfully delete all catalog entries by using the KILL option.

Program

Start a process (resource environment) by opening the catalog entry MATT in the WORK.SASMACR catalog.

 %macro matt;    %put &syscc;    %mend matt; 

Specify the KILL option to delete all catalog entries in WORK.SASMACR. Since there is a resource environment (process using the catalog), KILL will not work and an error is sent to the log.

 proc catalog c=work.sasmacr kill;  run;  quit; 

Log

 ERROR: You cannot open WORK.SASMACR.CATALOG for update access because         WORK.SASMACR.CATALOG is in use by you in resource environment         Line Mode Process.  WARNING: Command CATALOG not processed because of errors noted above.  NOTE: The SAS System stopped processing this step because of errors.  NOTE: PROCEDURE CATALOG used (Total process time):        real time           0.04 seconds        cpu time            0.03 seconds 

Add the FORCE Option to the PROC CATALOG Statement

Add the FORCE option to the KILL option to delete the catalog entries.

 proc catalog c=work.sasmacr kill force;  run;  quit; 

Log

 NOTE: Deleting entry MATT.MACRO in catalog WORK.SASMACR. 



Base SAS 9.1.3 Procedures Guide (Vol. 1)
Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4
ISBN: 1590472047
EAN: 2147483647
Year: 2004
Pages: 260

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net