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.
DATA sorttest (sortedby=priority descending indate);
2
INPUT priority indate date7. office $ code $;
3
FORMAT indate date7.;
4
DATALINES;
5
1 03may01 CH J8U
6
1 21mar01 LA M91
7
1 01dec00 FW L6R
8
1 27feb99 FW Q2A
9
2 15jan00 FW I9U
10
2 09jul99 CH P3Q
11
3 08apr99 CH H5T
12
3 31jan99 FW D2W
13
;
14
PROC CONTENTSDATA=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!
proc contents data=sashelp.snacks;
run;
1
PROC CONTENTSDATA=sashelp.snacks;
2
RUN;
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!
proc contents data=sashelp.air; run;
data air(sortedby=air);
set sashelp.air;
run;
proc contents data=air; run;
proc sort data=air; by descending air; run;
proc contents data=air; run;
1
PROC CONTENTSDATA=sashelp.air; RUN;
2
3
DATA air(sortedby=air);
4
SET sashelp.air;
5
RUN;
6
7
PROC CONTENTSDATA=air; RUN;
8
9
PROC SORTDATA=air; BY descending air; RUN;
10
PROC CONTENTSDATA=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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.