Chapter Contents

Previous

Next
The DATASETS Procedure

Concepts


Procedure Execution
When you start the DATASETS procedure, you specify the procedure input library in the PROC DATASETS statement. If you omit a procedure input library, the procedure processes the current default SAS data library (usually the WORK data library). To specify a new procedure input library, start the DATASETS procedure again.

Statements execute in the order they are written. For example, if you want to see the contents of a data set, copy a data set, and then compare the contents of the second data set with the first, the statements that perform those tasks must appear in that order (that is, CONTENTS, COPY, CONTENTS).

RUN-Group Processing

PROC DATASETS supports RUN-group processing. RUN-group processing enables you to submit RUN groups without ending the procedure.

The DATASETS procedure supports four types of RUN groups. Each RUN group is defined by the statements that compose it and by what causes it to execute.

Some statements in PROC DATASETS act as implied RUN statements because they cause the RUN group preceding them to execute.

The following list discusses what statements compose a RUN group and what causes each RUN group to execute:

The SAS System reads the program statements that are associated with one task until it reaches a RUN statement or an implied RUN statement. It executes all of the preceding statements immediately, then continues reading until it reaches another RUN statement or implied RUN statement. To execute the last task, you must use a RUN statement or a statement that stops the procedure.

The following PROC DATASETS step contains five RUN groups:

libname dest 'SAS-data-library';
   /* RUN group */
proc datasets;
      /* RUN group */
   change nutr=fatg;
   delete bldtest;
   exchange xray=chest;
      /* RUN group */
   copy out=dest;
      select report;
      /* RUN group */
   modify bp;
      label dias='Taken at Noon';
      rename weight=bodyfat;
      /* RUN group */
   append base=tissue data=newtiss;
quit;

Note:   If you are running in interactive line mode, you can receive messages that statements have already executed before you submit a RUN statement. Plan your tasks carefully if you are using this environment for running PROC DATASETS.  [cautionend]

Error Handling

Generally, if an error occurs in a statement, the RUN group containing the error does not execute. RUN groups preceding or following the one containing the error execute normally. The MODIFY RUN group is an exception. If a syntax error occurs in a statement subordinate to the MODIFY statement, only the statement containing the error fails. The other statements in the RUN group execute.

Note that if the first word of the statement (the statement name) is in error and the procedure cannot recognize it, the procedure treats the statement as part of the preceding RUN group.

Password Errors

If there is an error involving an incorrect or omitted password in a statement, the error only affects the statement containing the error. The other statements in the RUN group execute.

Forcing a RUN Group with Errors to Execute

The FORCE option in the PROC DATASETS statement forces execution of the RUN group even if one or more of the statements contain errors. Only the statements that are error-free execute.

Ending the Procedure

To stop the DATASETS procedure, you must issue a QUIT statement, a RUN CANCEL statement, a new PROC statement, or a DATA statement. Submitting a QUIT statement executes any statements that have not executed. Submitting a RUN CANCEL statement cancels any statements that have not executed.


Using Passwords with the DATASETS Procedure
Several statements in PROC DATASETS support options that manipulate passwords on SAS files. These options, ALTER=, PW=, READ=, and WRITE=, are also data set options.(footnote 1) If you do not know how passwords affect SAS files, refer to SAS Language Reference: Concepts.

When you are working with password-protected SAS files in the AGE, CHANGE, DELETE, EXCHANGE, REPAIR, or SELECT statement, you can specify password options in the PROC DATASETS statement or in a subordinate statement. The SAS System searches for passwords in the following order:

  1. in parentheses after the name of the SAS file in a subordinate statement. When used in parentheses, the option only refers to the name immediately preceding the option. If you are working with more than one SAS file in a data library and each SAS file has a different password, you must specify password options in parentheses after individual names.

    In the following statement, the ALTER= option provides the password RED for the SAS file BONES only:

    delete xplant bones(alter=red);

  2. after a forward slash (/) in a subordinate statement. When you use a password option following a slash, the option refers to all SAS files named in the statement unless the same option appears in parentheses after the name of a SAS file. This method is convenient when you are working with more than one SAS file and they all have the same password.

    In the following statement, the ALTER= option in parentheses provides the password RED for the SAS file CHEST, and the ALTER= option after the slash provides the password BLUE for the SAS file VIRUS:

       delete chest(alter=red) virus /
              alter=blue;

  3. in the PROC DATASETS statement. Specifying the password in the PROC DATASETS statement can be useful if all the SAS files you are working with in the library have the same password.

    In the following PROC DATASETS step, the PW= option provides the password RED for the SAS files INSULIN and ABNEG:

    proc datasets pw=red;
       delete insulin;
       contents data=abneg;
    run;

    Note:   For the password for a SAS file in a SELECT statement, the SAS System looks in the COPY statement before it looks in the PROC DATASETS statement.  [cautionend]


Restricting Member Types Available for Processing

In the PROC DATASETS Statement

If you name a member type or several member types in the PROC DATASETS statement, in most subsequent statements (the CONTENTS and COPY statements are exceptions to this rule) you can name only a subset of the list of member types included in the PROC DATASETS statement. The directory listing that the PROC DATASETS statement writes to the SAS log includes only those SAS files of the type specified in the MEMTYPE= option.

In Subordinate Statements

Use the MEMTYPE= option in the following subordinate statements to limit the member types that are available for processing:
AGE CHANGE DELETE EXCHANGE EXCLUDE REPAIR SAVE SELECT

Note:   The MEMTYPE= option works slightly differently for the CONTENTS and COPY statements. Refer to CONTENTS Statement and COPY Statement for more information.  [cautionend]

The procedure searches for MEMTYPE= in the following order:

  1. in parentheses immediately after the name of a SAS file. When used in parentheses, the MEMTYPE= option refers only to the SAS file immediately preceding the option. For example, the following statement deletes HOUSE.DATA, LOT.CATALOG, and SALES.DATA because the default member type for the DELETE statement is DATA. (Refer to Subordinate Statements and Appropriate Member Types for the default types for each statement.)
    delete house lot(memtype=catalog) sales;

  2. after a slash (/) at the end of the statement. When used following a slash, the MEMTYPE= option refers to all SAS files named in the statement unless the option appears in parentheses after the name of a SAS file. For example, the following statement deletes LOTPIX.CATALOG, REGIONS.DATA, and APPL.CATALOG:
    delete lotpix regions(memtype=data) appl
           / memtype=catalog;

  3. in the PROC DATASETS statement. For example, this PROC DATASETS step deletes APPL.CATALOG:
    proc datasets memtype=catalog;
       delete appl;
    run;

    Note:   When you use the EXCLUDE and SELECT statements, the procedure looks in the COPY statement for the MEMTYPE= option before it looks in the PROC DATASETS statement. For more information, see Specifying Member Types When Copying or Moving SAS Files .  [cautionend]

  4. for the default value. If you do not specify a MEMTYPE= option in the subordinate statement or in the PROC DATASETS statement, the default value for the subordinate statement determines the member type available for processing.


Member Types

The following list gives the possible values for the MEMTYPE= option:
ACCESS
access descriptor files (created by SAS/ACCESS software)

ALL
all member types

CATALOG
SAS catalogs

DATA
SAS data sets

FDB
financial database

MDDB
multidimensional database

PROGRAM
stored compiled SAS programs

VIEW
SAS data views

Subordinate Statements and Appropriate Member Types shows the member types that you can use in each statement:

Subordinate Statements and Appropriate Member Types
Statement Appropriate member types Default member type
AGE ACCESS, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW DATA
CHANGE ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW ALL
CONTENTS ALL, DATA, VIEW DATA (table note 1)
COPY ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW ALL
DELETE ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW DATA
EXCHANGE ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW ALL
EXCLUDE ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW ALL
MODIFY ACCESS, DATA, VIEW DATA
REPAIR ALL, CATALOG, DATA ALL (table note 2)
SAVE ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW ALL
SELECT ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW ALL

TABLE NOTE 1:  When DATA=_ALL_ in the CONTENTS statement, the default is ALL. ALL includes only DATA and VIEW. [arrow]

TABLE NOTE 2:  ALL includes only DATA and CATALOG. [arrow]


FOOTNOTE 1:  In the APPEND and CONTENTS statements, you use these options just as you use any SAS data set option, in parentheses after the SAS data set name. [arrow]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.