Published on :
ETL CREATION_INTERNE

Modifying SAS Data Sets

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
This example details the use of the DATASETS procedure to manage and modify attributes of SAS© data sets. It includes creating a composite index to improve search performance, applying formats and informats, assigning meaningful labels to variables and data sets, defining a sort order, and adding security via a read password. The goal is to demonstrate comprehensive and autonomous management of data set metadata and structure without external dependencies.
Data Analysis

Type : CREATION_INTERNE


Examples use generated data (datalines).

1 Code Block
PROC DATASETS Data
Explanation :
The program begins by setting system options (pagesize, linesize, nodate, pageno, source) and assigning the 'health' library to a file system path. Two fictitious data sets, 'group' and 'oxygen', are then created in this library to simulate test data.

The DATASETS procedure is then invoked with the NOLIST option to prevent displaying the library inventory. The MODIFY statement is used for the 'group' data set to add the label 'Test Subjects', assign a read password 'green', and specify that it is sorted by 'lname'. A composite index named 'vital' is created on the 'birth' and 'salary' variables, ensuring unique values and excluding missing observations. Formats and informats for the 'birth' variable are defined, and a detailed label is assigned to the 'salary' variable.

For the 'oxygen' data set, the MODIFY statement is used to rename the 'oxygen' variable to 'intake' and assign it a descriptive label. The procedure concludes with the QUIT statement.
Copied!
1options pagesize=40 linesize=80 nodate pageno=1 SOURCE;
2 
3LIBNAME health 'SAS-library';
4 
5/* Création de jeux de données fictifs pour l'exemple */
6DATA health.group;
7 INPUT lname $ birth :date7. salary;
8 FORMAT birth date7.;
9 DATALINES;
10Smith 01JAN80 50000
11Jones 15MAR85 60000
12Brown 20APR75 55000
13;RUN;
14 
15DATA health.oxygen;
16 INPUT oxygen;
17 DATALINES;
1810
1912
2011
21;RUN;
22 
23PROC DATASETS library=health nolist;
24 modify group (label='Test Subjects' read=green sortedby=lname);
25 index create vital=(birth salary) / nomiss unique;
26 informat birth date7.;
27 FORMAT birth date7.;
28 label salary='current salary excluding bonus';
29 modify oxygen;
30 rename oxygen=intake;
31 label intake='Intake Measurement';
32QUIT;
33 
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.
Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« lways use the NOLIST option in production environments to keep your SAS Log clean and focused on errors or warnings. Furthermore, remember that creating an index with the UNIQUE option will cause the procedure to fail if duplicates already exist, making it an excellent "last line of defense" for data quality. »