Vous êtes sur la page 1sur 16

INTRODUCTION

DATASETS procedure can do the work of PROC CONTENTS, COPY, and


APPEND put together and also do it very efficiently.
It is tool used to manage data and therefore does not generate an output in the
output window.
With DATASETS procedure one can
1. copy SAS files from one SAS library to another
2. rename SAS files
3. delete SAS files
4. list the SAS files that are contained in a SAS library
5. list the attributes of a SAS data set
6. append SAS data sets
7. modify attributes of SAS data sets and variables within the data sets


INTRODUCTION
SYNTAX:
PROC DATASETS <option-1 <...option-n>>;
Some of the Optional Arguments
KILL - -> deletes SAS files.
LIBRARY=libref - -> specifies the procedure input/output library.
MEMTYPE=(mtype(s)) - -> restricts processing to a certain type of SAS file.
NOLIST - -> suppresses the printing of the directory.
NOWARN - -> suppresses error processing.
DETAILS|NODETAILS - - > includes information in the log about the number of
observations, number of variables, number of indexes, and data set labels.

Syntax PROC DATASETS <optional arguments>;
QUIT; RUN;
Optional Arguments
KILL - Deletes all the datasets within a library automatically
LIBRARY - Specifies the procedure input or output library

Work is the default library in SAS.

If PROC DATASETS is used without a lib statement within the program, the library
used would be the last one referenced .

















SYNTAX
DATASETS
Given this code at the beginning of the session ,



Result will be a warning message in the Log.




DATASETS Vs CONTENTS


The output the statements is displayed in the LOG window.
Produces a list of all SAS datasets and catalogs that reside in the specified library
Similar to PROC CONTENTS

The above 2 statements generate exactly the same results; the DATASETS output goes
to to the LOG window & the CONTENTS output goes to the output window.




Both sends results to the OUTPUT window.
LOG WINDOW
COPY
COPY AN ENTIRE LIBRARY
The statements copy all the SAS files in the prajakta data library into the work data
library.


And the LOG window the following messages will appear.


EXCLUDE AND SELECT
COPYING OF SELECTED FILES
To copy selected SAS files , SELECT OR EXCLUDE statement is used.
EXCLUDE statement - prevents SAS files from copying
cannot appear in the same COPY statement with a SELECT
statement
SELECT statement selects SAS files for copying



Changing the keyword COPY to MOVE moves a member instead of copying it.
Datasets are in both libraries after copying
Datasets are only in the out = library after moving


SAVE, DELETE AND KILL
SAVE Or DELETE a Library dataset , KILL all Library members
The SAVE statement specifies which datasets will be kept in a SAS library. All others
not specified will be deleted.
The DELETE statement specifies which datasets will be deleted from the SAS library.
The KILL statement instructs SAS to delete all members in a library.

APPEND
To APPEND Datasets.
APPEND statement is used to concatenate 2 SAS datasets together .SAS takes one
dataset and appends the second dataset to the bottom of the first .
APPEND statement only reads in the observations from the dataset being appended.
General form of APPEND statement :
APPEND BASE = SAS dataset DATA = SAS dataset
The BASE = is the SAS dataset that you want the obs added to
The DATA = is the SAS dataset that you want added

APPEND
This example appends the def dataset to the bottom
of the abc dataset .
The contents statement is ran on the abc dataset
showing that the number of obs in the def dataset
have been added to abc.
CHANGE
To CHANGE the name of the SAS dataset
The CHANGE statement renames one or more SAS datasets within a SAS library.
The old name is specified on the left and the new name on the right.







MODIFY
To MODIFY SAS Datasets
MODIFY statement is used to specify dataset or variable attributes.
This statement specifies FORMATS, INFORMATS, LABEL, and RENAME variables.
The MODIFY statement only works on one SAS dataset at atime.
o Multiple variables can be labeled with one MODIFY statement.
o Multiple variables can be reanmed at a time.
o Formats and informats can be assigned to multiple variables.

Because no observations are read or written out during processing, for an existing SAS
dataset , the MODIFY statement is the best way to add a label, rename a variable, or
change a format or informat.
If the above changes made by using Data step, all of the observations are read in and
written out during processing.


MODIFY
Following is the example of MODIFY statement and the log.

RUN AND QUIT
For the DATASETS procedure only, SAS recognizes these statements as implied
RUN statements and therefore executes them immediately once they are submitted.
o APPEND statement
o CONTENTS statement
o MODIFY statement
o COPY statement
The RUN statement does not stop a PROC DATASETS step.
A QUIT statement or a new PROC statement or a DATA step must be submitted.
Submitting a QUIT statement executes any statement that are not executed and ends the
procedure.
CONCLUSION
PROC DATASETS a many featured , multi faceted, very useful tool. Since PROC
DATASETS does not read in nor write out observations, PROC DATASETS is very
efficient.
It is simple to use and easy to learn.
Caution should be exercised when working with the PROC DATASETS.
And realize that PROC DATASETS is an interactive procedure, so all statements
execute immediately and in the order they appear.

Vous aimerez peut-être aussi