The DATASETS Procedure |
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 library (usually the WORK 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).
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
CONTENTS
COPY
MODIFY
QUIT
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. SAS executes all of the preceding statements immediately and 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-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.
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.
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.
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.
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.(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 the subordinate statement.
Note: The ALTER= option works slightly different for the COPY (when moving a file) and MODIFY statements. Refer to COPY Statement and MODIFY Statement.
SAS searches for passwords in the following order:
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);
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;
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 |
If you reference more than one member type in subordinate statements and you have a specified member type in the PROC DATASETS statement, then include all of the member types in the PROC DATASETS statement. Only the member type or types in the original PROC DATASETS statement is in effect. The following example lists multiple member types:
proc datasets lib=library memtype=(data view);
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, COPY Statement, and MODIFY Statement for more information.
The procedure searches for MEMTYPE= in the following order:
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;
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;
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.
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.
The following list gives the possible values for the MEMTYPE= option:
access descriptor files (created by SAS/ACCESS software)
all member types
SAS catalogs
SAS data files
financial database
multidimensional database
stored compiled SAS programs
SAS views
Subordinate Statements and Appropriate Member Types shows the member types that you can use in each statement:
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.
TABLE NOTE 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.(footnote 2) 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.
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:
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);
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;
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.
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.
FOOTNOTE 2: 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.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.