Published on :
Data Access CREATION_INTERNE

Examples: Sorting and Displaying Descriptor Information for Data Sets

This code is also available in: Deutsch Español Français
Awaiting validation
Detailed functional analysis explaining the use of the SORTEDBY= option and the PROC CONTENTS and PROC SORT procedures to manage and visualize sorting metadata for SAS© data sets. The examples illustrate scenarios where the sort indicator is added, invalidated, or validated, and explain the implications of each sorting method.
Data Analysis

Type : CREATION_INTERNE


Examples use generated data (datalines) or SASHELP data sets.

1 Code Block
DATA STEP / PROC CONTENTS Data
Explanation :
This example uses the SORTEDBY= option to sort a 'sorttest' data set by 'priority' (descending) and 'indate'. Then, the PROC CONTENTS procedure is used to display the descriptive information of the sorted 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 example uses the PROC CONTENTS procedure to display descriptive information for the SAShelp.Snacks data set. This includes the number of observations, observation length, last modification date of the data set, and other facts, as well as the attributes of individual variables.
Copied!
1PROC CONTENTS DATA=sashelp.snacks;
2RUN;
3 Code Block
PROC CONTENTS
Explanation :
This example shows displaying sort information for the Sashelp.Air data set using PROC CONTENTS. The 'Sorted' field indicates 'NO', meaning the data set is not sorted and no sort indicator table is present.
Copied!
1PROC CONTENTS DATA=sashelp.air; RUN;
4 Code Block
DATA STEP / PROC CONTENTS
Explanation :
This example creates an 'air' data set from 'sashelp.air' and uses the 'sortedby=air' option in the DATA statement. PROC CONTENTS is then executed, showing that the data set is now marked as sorted, but with 'Validated' as 'NO', because SORTEDBY= does not generate a SAS-validated sort.
Copied!
1DATA air(sortedby=air);
2 SET sashelp.air;
3RUN;
4 
5PROC CONTENTS DATA=air; RUN;
5 Code Block
PROC SORT / PROC CONTENTS
Explanation :
This example sorts the 'air' data set by the 'air' variable in descending order using PROC SORT. Then, PROC CONTENTS is used to display the sort information, including the sort information table and the 'Validated' field set to 'YES', indicating a SAS-validated sort.
Copied!
1 
2PROC SORT
3DATA=air;
4BY descending air;
5 
6RUN;
7PROC CONTENTS
8DATA=air;
9 
10RUN;
11 
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


Related Documentation : Data Access

Sujet / Mot-cléLien vers la ressource
DOC FedSQL en/sampleCode/FEDSQL9D66
Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« In SAS, the sort indicator is a critical piece of metadata stored in the dataset descriptor. It acts as a "signal" to subsequent procedures (like PROC MEANS or MERGE) that the data is already ordered. Managing this indicator correctly is the key to bypassing redundant and resource-heavy sorting operations in large-scale production pipelines. »