Published on :
ETL SAS_LIBRARY

Modifying SAS Data Sets

This code is also available in: Deutsch Español Français
This document details the steps to modify two SAS© data sets, 'group' and 'oxygen'. Specific tasks include:
  • Adding a label to a data set.
  • Assigning a read password ('Read password') to a data set.
  • Specifying how data is sorted.
  • Creating a composite index ('VITAL') on the BIRTH and SALARY variables for the 'group' data set, with options to exclude observations with missing values (NOMISS) and ensure uniqueness (UNIQUE).
  • Assigning formats and informats to variables.
  • Renaming variables in a data set (e.g., 'oxygen' to 'intake').
  • Assigning labels to variables.
Data Analysis

Type : SAS_LIBRARY


The examples use data sets stored in a SAS library ('health') which must be defined (LIBNAME).

1 Code Block
OPTIONS, LIBNAME
Explanation :
Sets system options for the SAS log (page size, line size, date suppression, starting page number, source code display) and assigns the libname 'health' to a SAS library.
Copied!
1options pagesize=40 linesize=80 nodate pageno=1
2SOURCE;
3LIBNAME health 'SAS-library';
4 
2 Code Block
PROC DATASETS
Explanation :
Starts the DATASETS procedure, specifying 'health' as the input library and suppressing the display of the directory list (NOLIST).
Copied!
1PROC DATASETS library=health nolist;
3 Code Block
MODIFY (DATASETS)
Explanation :
Modifies the 'group' data set: assigns the label 'Test Subjects', sets 'green' as the read password, and specifies 'lname' as the sorting variable.
Copied!
1modify group (label='Test Subjects' read=green sortedby=lname);
2 
4 Code Block
INDEX CREATE (DATASETS)
Explanation :
Creates a composite index named 'vital' on the 'birth' and 'salary' variables. The NOMISS option excludes observations with missing values. The UNIQUE option ensures that each combination of values is unique.
Copied!
1index create vital=(birth salary) / nomiss unique;
2 
5 Code Block
INFORMAT, FORMAT, LABEL (DATASETS)
Explanation :
Applies the 'date7.' informat and format to the 'birth' variable. Assigns the label 'current salary excluding bonus' to the 'salary' variable.
Copied!
1informat birth date7.;
2FORMAT birth date7.;
3label salary='current salary excluding bonus';
4 
6 Code Block
MODIFY, RENAME, LABEL (DATASETS)
Explanation :
Modifies the 'oxygen' data set: renames the variable 'oxygen' to 'intake' and assigns the label 'Intake Measurement' to the new variable. The QUIT statement terminates the DATASETS procedure.
Copied!
1 modify oxygen;
2 rename oxygen=intake;
3 label intake='Intake Measurement';
4QUIT;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved