Published on :
ETL CREATION_INTERNE

Examples: Sort and Display Descriptive Information for Data Sets

This code is also available in: Deutsch Español Français
Awaiting validation
The functional analysis details three main scenarios: sorting a data set using the SORTEDBY= option in a DATA step, displaying the descriptive information of a data set with PROC CONTENTS, and visualizing the sort information of a data set. Each section presents the corresponding SAS© code, its execution, and associated outputs or key concepts. Special attention is paid to the distinction between 'validated' sorting (performed by PROC SORT or PROC SQL) and 'unvalidated' sorting (defined via the SORTEDBY= option in a DATA step).
Data Analysis

Type : CREATION_INTERNE


The examples use internally generated data via the DATALINES statement and data sets from the SASHELP library (SASHELP.SNACKS and SASHELP.AIR) to demonstrate concepts without relying on external data sources.

1 Code Block
DATA STEP / PROC CONTENTS Data
Explanation :
This example uses the SORTEDBY= data set option to indicate that the 'sorttest' data set is sorted by 'priority' (ascending order) and then by 'indate' (descending order). The CONTENTS procedure is then used to display the descriptive information of the data set, including the sort indicator.
Copied!
1DATA sorttest (sortedby=priority descending indate);
2 INPUT priority indate date7. office $ code $;
3 FORMAT indate date7.;
4 DATALINES;
51 03may01 CH J8U
61 21mar01 LA M91
71 01dec00 FW L6R
81 27feb99 FW Q2A
92 15jan00 FW I9U
102 09jul99 CH P3Q
113 08apr99 CH H5T
123 31jan99 FW D2W
13;
14PROC CONTENTS DATA=sorttest; RUN;
2 Code Block
PROC CONTENTS
Explanation :
This simple example uses the CONTENTS procedure to display descriptive information for the SASHELP.SNACKS data set. This includes metadata such as the number of observations, last modified date, variable attributes (name, type, length, format, label), and whether the data set is sorted.
Copied!
1PROC CONTENTS DATA=sashelp.snacks;
2RUN;
3 Code Block
PROC CONTENTS / DATA STEP / PROC SORT Data
Explanation :
This three-part example shows how sort information is reflected in a data set's metadata. First, it displays information for unsorted 'Sashelp.Air'. Then, it creates a copy of the 'air' data set using the SORTEDBY= option in the DATA statement, showing that the sort indicator is present but unvalidated. Finally, it uses PROC SORT to sort the 'air' data set by the 'air' variable in descending order, resulting in 'validated' sorting as indicated by the CONTENTS procedure.
Copied!
1PROC CONTENTS DATA=sashelp.air; RUN;
2 
3DATA air(sortedby=air);
4 SET sashelp.air;
5RUN;
6 
7PROC CONTENTS DATA=air; RUN;
8 
9PROC SORT DATA=air; BY descending air; RUN;
10PROC CONTENTS DATA=air; RUN;
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