The DOCUMENT Procedure

Example 6: Listing BY-Group Entries

Features:
LIST statement options:
BYGROUPS
LEVELS
LIST

PROC DOCUMENT statement option: NAME=

OBTEMPL statement

Procedure output :
PROC DOCUMENT
PROC STANDARD
ODS destinations: DOCUMENT

HTML

Details

This example shows you how to do these tasks:
  • generate PROC STANDARD output to the DOCUMENT destination
  • view the table template that describes how to display the PROC STANDARD output
  • create an ODS document
  • open an ODS document
  • list the BY group entries in an ODS document

Program

options nodate nonumber;
ods document name=mydocument(write);
data score;
   input Student Section Test1-Test3;
   stest1=test1;
   stest2=test2;
   stest3=test3;
   datalines;
238900545 1 94 91 87
254701167 1 95 96 97
238806445 2 91 86 94
999002527 2 80 76 78
263924860 1 92 40 85
459700886 2 75 76 80
416724915 2 66 69 72
999001230 1 82 84 80
242760674 1 75 76 70
990001252 2 51 66 91
;
run;

proc sort data=score;
   by Section Student;
run;
proc standard mean=80 std=5 out=StndScore print;
   by section student;
   var stest1-stest3;
run;
ods document close;
proc document name=mydocument;
title "Listing of MyDocument Using the BYGROUPS Option"; 
run;
   list/ levels=all bygroups;
run; 
title "Table Template for the Output Object Standard#1";
   obtempl \Standard#1\ByGroup1#1\Standard#1;
run;
quit;

Program Description

Set the SAS system options, create the ODS document MyDocument, and open the DOCUMENT destination. The NODATE option suppresses the display of the date and time in the output. The NONUMBER option suppresses the printing of page numbers. The ODS DOCUMENT statement with the NAME= option specified opens the ODS document MyDocument and provides Write access as well as Read access. Note that by default MyDocument will be created in the Work library. Assign a libref to create MyDocument in a permanent library.
options nodate nonumber;
ods document name=mydocument(write);
Create and sort the Score data set. This data set contains test scores for students who took two tests and a final exam. The SORT procedure sorts the data set by the BY variables Section and Student.
data score;
   input Student Section Test1-Test3;
   stest1=test1;
   stest2=test2;
   stest3=test3;
   datalines;
238900545 1 94 91 87
254701167 1 95 96 97
238806445 2 91 86 94
999002527 2 80 76 78
263924860 1 92 40 85
459700886 2 75 76 80
416724915 2 66 69 72
999001230 1 82 84 80
242760674 1 75 76 70
990001252 2 51 66 91
;
run;

proc sort data=score;
   by Section Student;
run;
Generate the standardized data and create the output data set StndScore. PROC STANDARD uses a mean of 80 and a standard deviation of 5 to standardize the values. OUT= identifies StndScore as the data set to contain the standardized values. The PRINT option prints the statistics.
proc standard mean=80 std=5 out=StndScore print;
Create the standardized values for each BY group and specify the variables to standardize. The BY statement standardizes the values separately by section number and student ID. The VAR statement specifies the variables to standardize and their order in the output.
   by section student;
   var stest1-stest3;
run;
Close the DOCUMENT destination. If the DOCUMENT destination is not closed, no DOCUMENT procedure output can be viewed.
ods document close;
Open the ODS document MyDocument, list the entries, and view the table template that determines how the PROC STANDARD output will display. The PROC DOCUMENT statement with the NAME= option specified opens the ODS document Work.MyDocument. The LIST statement with the LEVELS=ALL option lists detailed information about all levels of the document Work.MyDocument. The BYGROUPS option creates columns in the list statement output for BY group information. The names of the columns with the BY group information are the names of the BY variables, Section and Student. The OBTEMPL statement writes the table template that is associated with the output object Standard#1 to the HTML destination. The ODS DOCUMENT CLOSE statement closes the DOCUMENT destination. If the DOCUMENT destination is not closed, no DOCUMENT procedure output can be viewed. If you omit LEVELS=ALL, then no entry list will be created. This is because ODS cannot find any BY groups at the directory level and only BY groups are listed when the BYGROUPS option is specified.
To see what the output will look like if you omit the BYGROUPS option, see Listing of Work.MyDocument with the BYGROUPS Option Specified.
proc document name=mydocument;
title "Listing of MyDocument Using the BYGROUPS Option"; 
run;
   list/ levels=all bygroups;
run; 
title "Table Template for the Output Object Standard#1";
   obtempl \Standard#1\ByGroup1#1\Standard#1;
run;
Terminate the DOCUMENT procedure. Specify the QUIT statement to terminate the DOCUMENT procedure. If you omit QUIT, then you will not be able to view DOCUMENT procedure output.
quit;

Output

Without the BYGROUPS option specified, there are only three columns for this output: Obs, Path, and Type. All levels and all entries of Work.MyDocument are displayed.
Listing of Work.MyDocument without the BYGROUPS Option Specified
Listing of Work.MyDocument without the BYGROUPS Option Specified
With the BYGROUPS option specified there are now five columns. The additional columns, named Section and Student, were created by the BYGROUPS option. The BY variable names become the names of the columns. Only the entries containing BY group information are displayed. The entries that are directories are not displayed because they do not contain any actual BY group information.
Listing of Work.MyDocument with the BYGROUPS Option Specified
Listing of Work.MyDocument with the BYGROUPS Option Specified
Table Template Associated with PROC STANDARD Output
Table Template for the Output Object Standard#1