DATASETS Procedure

Example 10: Using the ORDER= Option with the CONTENTS Statement

Features:
CONTENTS statement options:
ORDER=
COLLATE
CASECOLLATE
IGNORECASE
VARNUM

Program

options nonotes nodate nonumber nocenter formdlim  ='-';

libname contents 'C:\proccontents';

data contents.test;
   d=2;
   b001 =1;
   b002 =2;
   b003 =3;
   b001z=1;
   B001a=2;
   CaSeSeNsItIvE2=9;
   CASESENSITIVE3=9;
   D=2;
   casesensitive1=9;
   CaSeSeNsItIvE1a=9;
   d001z=1;
   CASESENSITIVE1C=9;
   D001a=2;
   casesensitive1b=9;
   A =1;
   a002 =2;
   a =3;
   a001z=1;
   A001a=2;

run;
%let mydata=contents.test;

ods output Variables=var1(keep=Num Variable);
ods listing close;

proc contents data=&mydata;
run;

ods listing;
    title "Default options";

proc print data=var1 noobs;
run;

ods output Variables=var2(keep=Num Variable);
ods listing close;

proc contents order=collate data=&mydata;
run;

ods listing;
    title "order=collate option";

proc print data=var2 noobs;
run;

ods output Variables=var3(keep=Num Variable);
ods listing close;

proc contents order=casecollate data=&mydata;
run;

ods listing;
    title "order=casecollate option";

proc print data=var3 noobs;
run;

ods output Variables=var4(keep=Num Variable);
ods listing close;

proc contents order=ignorecase data=&mydata;
run;

ods listing;
    title "order=ignorecase option";

proc print data=var4 noobs;
run;
ods output Position=var5(keep=Num Variable);
ods listing close;

proc contents data=&mydata varnum;
run;

ods listing;
    title "varnum option";

proc print data=var5 noobs;
run;  

Program Description

Set up the data set.
options nonotes nodate nonumber nocenter formdlim  ='-';

libname contents 'C:\proccontents';

data contents.test;
   d=2;
   b001 =1;
   b002 =2;
   b003 =3;
   b001z=1;
   B001a=2;
   CaSeSeNsItIvE2=9;
   CASESENSITIVE3=9;
   D=2;
   casesensitive1=9;
   CaSeSeNsItIvE1a=9;
   d001z=1;
   CASESENSITIVE1C=9;
   D001a=2;
   casesensitive1b=9;
   A =1;
   a002 =2;
   a =3;
   a001z=1;
   A001a=2;

run;
To produce PROC CONTENTS output for a data set of your choice, change data set name to MYDATA.
%let mydata=contents.test;

ods output Variables=var1(keep=Num Variable);
ods listing close;

proc contents data=&mydata;
run;

ods listing;
    title "Default options";

proc print data=var1 noobs;
run;

ods output Variables=var2(keep=Num Variable);
ods listing close;

proc contents order=collate data=&mydata;
run;

ods listing;
    title "order=collate option";

proc print data=var2 noobs;
run;

ods output Variables=var3(keep=Num Variable);
ods listing close;

proc contents order=casecollate data=&mydata;
run;

ods listing;
    title "order=casecollate option";

proc print data=var3 noobs;
run;

ods output Variables=var4(keep=Num Variable);
ods listing close;

proc contents order=ignorecase data=&mydata;
run;

ods listing;
    title "order=ignorecase option";

proc print data=var4 noobs;
run;
VARNUM option is used.Note that the name of the ODS output object is different when the VARNUM option is used.
ods output Position=var5(keep=Num Variable);
ods listing close;

proc contents data=&mydata varnum;
run;

ods listing;
    title "varnum option";

proc print data=var5 noobs;
run;  

Using the COLLATE and CASECOLLATE Options

The following output shows the results of the ORDER= default, the COLLATE option, and the CASECOLLATE option.
Using the COLLATE and CASECOLLATE Options
The following output shows the results of the ORDER= default, IGNORECASE option, and VARNUM option.
Results of Using the IGNORECASE and VARNUM Options
Results of Using the IGNORECASE and VARNUM Options

Results

The following output shows the results of the ORDER= default, the COLLATE option, and the CASECOLLATE option:
The following table shows the results of the ORDER= default, IGNORECASE option, and VARNUM option.
Results of Using the IGNORECASE and VARNUM Options
default
IGNORECASE
VARNUM
Num    Variable

15     A
18     A001a
 6     B001a
 8     CASESENSITIVE3
12     CASESENSITIVE1C
 7     CaSeSeNsItIvE2
10     CaSeSeNsItIvE1a
13     D001a
16     a002
17     a001z
 2     b001
 3     b002
 4     b003
 5     b001z
 9     casesensitive1
14     casesensitive1b
 1     d
11     d001z          
Num    Variable

15     A
16     a002
18     A001a
17     a001z
 2     b001
 3     b002
 4     b003
 6     B001a
 5     b001z
 9     casesensitive1
 7     CaSeSeNsItIvE2
 8     CASESENSITIVE3
10     CaSeSeNsItIvE1a
14     casesensitive1b
12     CASESENSITIVE1C
 1     d
13     D001a
11     d001z            
Num    Variable

 1     d
 2     b001
 3     b002
 4     b003
 5     b001z
 6     B001a
 7     CaSeSeNsItIvE2
 8     CASESENSITIVE3
 9     casesensitive1
10     CaSeSeNsItIvE1a
11     d001z
12     CASESENSITIVE1C
13     D001a
14     casesensitive1b
15     A
16     a002
17     a001z
18     A001a