DATASETS Procedure

Example 4: Modifying SAS Data Sets

Features:

PROC DATASETS statement option: NOLIST

FORMAT statement

INDEX CREATE statement options:
NOMISS
UNIQUE

INFORMAT statement

LABEL statement

MODIFY statement options:
LABEL=
READ=
SORTEDBY=

RENAME statement

Details

This example modifies two SAS data sets using the MODIFY statement and statements subordinate to it. Describing a SAS Data Set shows the modifications to the GROUP data set.
This example includes the following actions:
  • modifying SAS files
  • labeling a SAS data set
  • adding a Read password to a SAS data set
  • indicating how a SAS data set is currently sorted
  • creating an index for a SAS data set
  • assigning informats and formats to variables in a SAS data set
  • renaming variables in a SAS data set
  • labeling variables in a SAS data set

Program

options pagesize=40 linesize=80 nodate pageno=1 source;
LIBNAME health
'SAS-library';
proc datasets library=health nolist;
   modify group (label='Test Subjects' read=green sortedby=lname);
      index create vital=(birth salary) / nomiss unique;
      informat birth date7.;
      format birth date7.;
      label salary='current salary excluding bonus';
   modify oxygen;
      rename oxygen=intake;
      label intake='Intake Measurement';
quit;

Program Description

Write the programming statements to the SAS log. SAS option SOURCE writes the programming statements to the log.
options pagesize=40 linesize=80 nodate pageno=1 source;
LIBNAME health
'SAS-library';
Specify HEALTH as the procedure input library to process. NOLIST suppresses the directory listing for the HEALTH data library.
proc datasets library=health nolist;
Add a label to a data set, assign a Read password, and specify how to sort the data. LABEL= adds a data set label to the data set GROUP. READ= assigns GREEN as the Read password. The password appears as Xs in the SAS log. SAS issues a warning message if you specify a level of password protection on a SAS file that does not include Alter protection. SORTEDBY= specifies how the data is sorted.
   modify group (label='Test Subjects' read=green sortedby=lname);
Create the composite index VITAL on the variables BIRTH and SALARY for the GROUP data set. NOMISS excludes all observations that have missing values for BIRTH and SALARY from the index. UNIQUE specifies that the index is created only if each observation has a unique combination of values for BIRTH and SALARY.
      index create vital=(birth salary) / nomiss unique;
Assign an informat and format, respectively, to the BIRTH variable.
      informat birth date7.;
      format birth date7.;
Assign a label to the variable SALARY.
      label salary='current salary excluding bonus';
Rename a variable, and assign a label. Modify the data set OXYGEN by renaming the variable OXYGEN to INTAKE and assigning a label to the variable INTAKE.
   modify oxygen;
      rename oxygen=intake;
      label intake='Intake Measurement';
quit;

SAS Log


169  options pagesize=40 linesize=80 nodate pageno=1 source;
170  LIBNAME health 'c:\Documents and Settings\mydir\My
170! Documents\procdatasets\health';
NOTE: Libref HEALTH was successfully assigned as follows:
      Engine:        V9
      Physical Name: c:\Documents and Settings\mydir\My
      Documents\procdatasets\health

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           8:06.11
      cpu time            0.54 seconds


171  proc datasets library=health nolist;
172   modify group (label='Test Subjects' read=XXXXX sortedby=lname);
WARNING: The file HEALTH.GROUP.DATA is not ALTER protected.  It could be
         deleted or replaced without knowing the password.
173   index create vital=(birth salary) / nomiss unique;
NOTE: Composite index vital has been defined.
NOTE: MODIFY was successful for HEALTH.GROUP.DATA.
174  informat birth date7.;
175  format birth date7.;
176  label salary='current salary excluding bonus';
177  modify oxygen;
178  rename oxygen=intake;
NOTE: Renaming variable oxygen to intake.
179  label intake='Intake Measurement';
180  quit;

NOTE: MODIFY was successful for HEALTH.OXYGEN.DATA.
NOTE: PROCEDURE DATASETS used (Total process time):
      real time           15.09 seconds
      cpu time            0.06 seconds