Concepts: DATASETS Procedure


Procedure Execution

Execution of Statements

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, issue 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 visually 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 PROC DATASETS statement always executes immediately. No other statement is necessary to cause the PROC DATASETS statement to execute. Therefore, the PROC DATASETS statement alone is a RUN group.

  • The MODIFY statement, and any of its subordinate statements, form a RUN group. These RUN groups always execute immediately. No other statement is necessary to cause a MODIFY RUN group to execute.

  • The APPEND, CONTENTS, and COPY statements (including EXCLUDE and SELECT, if present), form their own separate RUN groups. Every APPEND statement forms a single-statement RUN group; every CONTENTS statement forms a single-statement RUN group; and every COPY step forms a RUN group. Any other statement in the procedure, except those that are subordinate to either the COPY or MODIFY statement, causes the RUN group to execute.

  • One or more of the following statements form a RUN group:

    • AGE

    • CHANGE

    • DELETE

    • EXCHANGE

    • REPAIR

    • SAVE

  • If any of these statements appear in sequence in the PROC step, the sequence forms a RUN group. For example, if a REPAIR statement appears immediately after a SAVE statement, the REPAIR statement does not force the SAVE statement to execute; it becomes part of the same RUN group. To execute the RUN group, submit one of the following statements:

    • PROC DATASETS

    • APPEND

    • MODIFY

    • COPY

    • QUIT

    • CONTENTS

    • RUN

    • another DATA or PROC step.

SAS 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.

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 affects only 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 the DATASETS procedure support options that manipulate passwords on SAS files. These options, ALTER=, PW=, READ=, and WRITE=, are also data set options. [*] 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 the subordinate statement.

Note: The ALTER= option works slightly different for the COPY (when moving a file) and MODIFY statements. Refer to COPY Statement on page 323 and MODIFY Statement on page 344.

SAS 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. Do not specify the option in parentheses.

    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, SAS looks in the COPY statement before it looks in the PROC DATASETS statement.

Restricting Member Types 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 (except the CONTENTS and COPY statements), 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, COPY, and MODIFY statements. Refer to CONTENTS Statement on page 319, COPY Statement on page 323, and MODIFY Statement on page 344 for more information.

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 Table 15.5 on page 358 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 DATASETS procedure 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 on page 327.

  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 files

FDB

  • financial database

MDDB

  • multidimensional database

PROGRAM

  • stored compiled SAS programs

VIEW

  • SAS views

Table 15.5 on page 358 shows the member types that you can use in each statement:

Table 15.5: 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 [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 [2]

SAVE

ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW

ALL

SELECT

ACCESS, ALL, CATALOG, DATA, FDB, MDDB, PROGRAM, VIEW

ALL

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

[2] ALL includes only DATA and CATALOG.

Restricting Processing for Generation Data Sets

Several statements in the DATASETS procedure support the GENNUM= option to restrict processing for generation data sets. GENNUM= is also a data set option. [*] If you do not know how to request and use generation data sets, refer to Generation Data Sets in SAS Language Reference: Concepts .

When you are working with a generation group for the AUDIT, CHANGE, DELETE, MODIFY, and REPAIR statements, you can restrict processing in the PROC DATASETS statement or in the subordinate statement to a specific version.

Note: The GENNUM= option works slightly different for the MODIFY statement. See MODIFY Statement on page 344.

Note: You cannot restrict processing to a specific version for the AGE, COPY, EXCHANGE, and SAVE statements. These statements apply to the entire generation group.

SAS searches for a generation specification in the following order:

  1. in parentheses after the name of the SAS data set 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 data set in a data library and you want a different generation version for each SAS data set, you must specify GENNUM= in parentheses after individual names.

    In the following statement, the GENNUM= option specifies the version of a generation group for the SAS data set BONES only:

     delete xplant bones (gennum=2); 
  2. after a forward slash (/) in a subordinate statement. When you use the GENNUM= option following a slash, the option refers to all SAS data sets named in the statement unless the same option appears in parentheses after the name of a SAS data set. This method is convenient when you are working with more than one file and you want the same version for all files.

    In the following statement, the GENNUM= option in parentheses specifies the generation version for SAS data set CHEST, and the GENNUM= option after the slash specifies the generation version for SAS data set VIRUS:

     delete chest (gennum=2) virus / gennum=1; 
  3. in the PROC DATASETS statement. Specifying the generation version in the PROC DATASETS statement can be useful if you want the same version for all of the SAS data sets you are working with in the library. Do not specify the option in parentheses.

    In the following PROC DATASETS step, the GENNUM= option specifies the generation version for the SAS files INSULIN and ABNEG:

     proc datasets gennum=2;     delete insulin;     contents data=abneg;  run; 

    Note: For the generation version for a SAS file in a SELECT statement, SAS looks in the COPY statement before it looks in the PROC DATASETS statement.

[*] 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.

[*] For the APPEND and CONTENTS statements, use GENNUM= just as you use any SAS data set option, in parentheses after the SAS data set name.




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