Adding Column Totals and Subtotals, Observation Counts, and Footnotes - SAS Programming

This next example includes summary data of various kinds, footnotes and titles, and some overall system formatting options. In addition, each DIAGCODE group is processed individually. Here is the program:

Example

OPTIONS NOCENTER NODATE NONUMBER;
PROC SORT DATA=MEDICAL; <l
BY DIAGCODE;
RUN;
&
PROC PRINT DATA=MEDICAL N LABEL;
BY DIAGCODE; €»
TITLE 'Hospital Data Base Report';
TITLE2 ' ';
FOOTNOTE 'Prepared by RPC and Company'; 0
SUM LOS COST? 0
SUMBY DIAGCODE; ©
ID SUBJCD;
VAR DIAGCODE
ADMIT_DT
DISCHJ>T
HOSPCODE
LOS
COST;
LABEL DIAGCODE «• 'Diagnosis Code'
ADMITJ3T - 'Admission Date'
DISCHJXF •» 'Discharge Date'
HOSPCODE « 'Hospital Code'
LOS * 'Length of Stay'
COST * 'Cost of Treatment';
FORMAT COST DOLLAR?,
SUB_ID SSN11.
ADMIT_DT DISCH DT MMDDYY8.;
RUN;

You use PROC SORT to sort the data set by DIAGCODE, assuming that is isn't already in the desired order.O Actually, the SAS System does not re-sort a data set if it has been previously sorted by a SORT procedure.It does,however, inform you that a re-sort is not necessary. It is not enough merely to sort the data set; you also have to tell the procedure that you want to process the data set by the BY group as well.This is accomplished with the BY statement in the PRINT procedure. © Keep in mind that the BY statement in the SORT procedure tells the system how to sort the data, and the BY statement in the other procedures tells the system to use the BY groups created by the SORT procedure.Your report appears in multiple sections, one for each BY group, with an identifying BY line above each subgroup.

You add the N option © to obtain the number of observations in the data set.When a BY variable(s) is used, the N option also indicates the number of observations for each value of the BY variable(s).© The FOOTNOTE statement © is like a TITLE statement except that the text following a FOOTNOTE statement appears on the bottom of each page of the report.

The SUM statement © prints sums for the listed variables, LOS and COST in this case.The SUMBY statement ©, which can only be used when you have a BY variable(s), gives the sums of the indicated variables for each value of the SUMBY variable(s). Here is the final output.Note that only selected portions of the output are shown.

Output from Example - Adding Column Totals and Subtotals, Observation Counts, and Footnotes

Output from Example - Adding Column Totals and Subtotals, Observation Counts, and Footnotes

Output from Example - Adding Column Totals and Subtotals, Observation Counts, and Footnotes

This example uses some SAS system options that affect the appearance of the listings from PROC PRINT.Your titles are left aligned instead of centered (as they are for most of the sample listings in this book),and you omit the time, date, and page number.You may also want to start page numbering at a number of your choosing. An OPTIONS statement, placed at any point in your SAS program,will alter the selected options from that point on until they are changed. For example,to left align your titles, omit the date and time, and start page numbering at 1,write the OPTIONS statement like this:

OPTIONS NOCENTER NODATE PAGENO=1;

If at some later point in the program (before another PROC PRINT most likely) you want the title centered and you want to restart the page numbering from 1, you would use:

OPTIONS CENTER PAGENO=1;

Other useful OPTIONS are PAGESIZE= and LINESIZE=(abbreviated as PS and LS respectively).Use these two options to control the number of lines printed per page and the number of characters per line. Valid values for PAGESIZE are from 15 to 32,767; for LINESIZE from 64 to 256.

Dealing with Multi-Page Reports

PROC PRINT provides options(available since Release 6.07) which allow you some control over column widths and overall column placement on multi-page reports.The PROC PRINT option WIDTH= allows you to choose FULL, MINIMUM, UNIFORM, or UNIFORMSY.To demonstrate some of these options, let's redo a simple version of the above code using WIDTH=FULL and WIDTH=MINIMUM.First we'll set WIDTH=FULL, and then we'll use WIDTH=MINIMUM.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics