Increasing Readability - SAS Programming

The next step to improve this simple report is to include format and label information, along with titles.First the code:

Example

PROC PRINT DATA=MEDICAL WIDTH=FULL;
TITLE 'WIDTH option FULL';
VAR SUB_ID
DIAGCODE
ADMITJ5T
DISCH_DT
HOSPCODE
LOS
COST;
FORMAT COST DOLLAR?.
SUB_ID SSNll,
ADMIT_DT DISCH_DT MMDDYY8.;
RUN;
LABEL DIAGCODE='Diagnosis Code' &
ADMITJJT-'Admission Date'
DISCH_J)T«'Discharge Date'
HOSPCODE*'Hospital Code'
LOS -'Length of Stay'
COST -'Cost of Treatment';
FORMAT COST DOLLAR?. @
SUB_ID SSN11.
ADMITJDT DISCHJJT MMDDYY8.?
RUN;

The first thing to notice is the use of both a LABEL option on the PROC PRINT statement O and a separate LABEL statement ©.These do different things.The LABEL statement defines a set of variable labels which can be used instead of variable names as the column headings.The LABEL option tells the system to actually use the labels that are created in the LABEL statement.Just creating the labels in the statement without turning them on with the option will not do the trick.An aside: you created the variables'labels in this PRINT procedure.They also could have been created with a LABEL statement in the DATA step that was used to create the data set MEDICAL.

The difference in the two placements is as follows: when a LABEL statement appears in a procedure, it makes available a set of labels for that procedure only. When a LABEL statement is used in a DATA step (when the data set is being created),the labels are available for any subsequent procedures which operate on the data set.

The next enhancement is the formatting of the COST, SUB_ID, ADMIT_DT, and DISCH_DT variables.This is done with the FORMAT statement 0.This statement, like the LABEL statement,also could have appeared in the DATA step.Unlike the LABEL statement,it does not have to be turned on with a separate option.Notice that the SSN11. format adds the leading zeroes as well as the dashes to the data when displaying them as Social Security numbers. Pretty slick! The DOLLAR/, format also automatically includes the commas.

The final enhancement in this example to make the output more useful and readable is to use titles. © In Example 1 you saw the default SAS System title (the words "The SAS System"),the time and date of the run, and the page number.In this example you create your own custom titles. Titles in TITLE statements are enclosed in quotation marks, either single or double but they must match.

You can have up to 10 title lines (TITLE and TITLE 1 are equivalent.)Titles are not specifically PROC PRINT statements - they can be used anywhere in a SAS program.They remain in effect until they are replaced or nullified with null TITLE statements of the form TITLEn;this will clear all titles of number n or greater.)Here is the resulting output from Example 3:

Output from Example - Increasing Readability

Output from Example  - Increasing Readability

Notice that the labels you create are automatically split into multi-row labels by the system as it sees fit. If you want to, you can instruct the system how to split the labels by defining a split-character on the PROC PRINT statement with the SPLTT=char option, and then placing your chosen character in the labels where you want the line splits to occur.

Note that the SPLIT= option implicitly includes the LABEL option - it is not necessary to code the LABEL option when defining a split-character. This code defines the asterisk (*) as a split character and creates the following labels:

PROC PRINT DATA=MEDICAL LABEL SPLIT='*';
LABEL DIAGCODE='Diagnosis*Code'
ADMIT_DT='Admission*Date'
DISCH_DT='Discharge*Date'
HOSPCODE='Hospital*Code'
LOS ='Length*of*Stay'
COST ='Cost*of*Treatment';

Labels produced using the * split-character appear as follows:

split-character


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

SAS Programming Topics