using proc_codebook.sas - Carolina Population Center

advertisement
USING PROC_CODEBOOK.SAS
Kim Chantala
kim_chantala@unc.edu
Department of Health Behavior & Health Education
Gillings School of Global Public Health
UNC at Chapel Hill
Jim Terry
jwterry@unc.edu
Carolina Population Center
UNC at Chapel Hill
Last update: April 27, 2010
PROC_CODEBOOK.SAS is a SAS macro program that can be used to create a comprehensive, well formatted and
easy to read codebook. The program is simple to use, requiring the user to only specify one or two titles for the
codebook, define the file organization, and provide a SAS data set that has labels and formats assigned to
variables. Here is sample code showing how easy it is to use:
*Include SAS code for variable formats, PROC_CODEBOOK macro program;
%include 'C:\My_project\HWT_short_formats.sas';
%include ' C:\My_project\proc_codebook.sas';
*User defines folder where data set resides;
libname here 'C:\My_project';
*User specifies titles for codebook PDF file;
title1 'CODEBOOK FOR WAY TO HEALTH BASELINE HEIGHT/WEIGHT DATA';
footnote 'Created by: hwt_base_codebook.sas';
%let organization=One Record per Participant (ID);
*Run Codebook macro;
%proc_codebook(lib=here,
file1=hwt_base,
fmtlib=work.formats,
pdffile=hwt_base_codebook.pdf);
run;
1
SAS Output:
Detailed Instructions for using the PROC_CODEBOOK.SAS macro and creating the SAS data set are provided in
the remainder of this document.
RECOMMENDED REQUIREMENTS FOR THE SAS FILE TO BE DOCUMENTED





Have labels on all variables.
The data set must contain at least one categorical variable and two numeric variables.
Have user FORMATs assigned to all categorical variables. Standard formats should be used that assign only
one value (not a list of values) or a range of values to a unique value label. No testing has been done using
hybrid formats or formats with multi-value labels.
Have a data set label on the SAS data file.
By default, the codebook is ordered by Variable Name. See the instructions in the section “ORDERING
VARIABLES IN CODEBOOK” section to control order of variables are listed in codebook.
2
ORDERING VARIABLES IN CODEBOOK
Create a simple two variable file called work.order before you call the macro. The first variable is NAME, a 32
character field with your variable name in UPPER CASE. The second variable is ORDER, a numeric field with the
order you want the variables to print. An example data step creating a work.order data set is shown below.
data order;
length name $ 32;
name = "T1
"; ORDER
name = "HHID09"; ORDER
name = "LINE09"; ORDER
name = "H1D
"; ORDER
run;
=
=
=
=
1;
2;
3;
4;
OUTPUT;
OUTPUT;
OUTPUT;
OUTPUT;
TITLES AND FOOTNOTES
TITLE1, TITLE2 and all FOOTNOTES are specified by user. PROC_CODEBOOK creates the following titles:
 TITLE4 lists the number of observations in Data set.
 TITLE5 lists the number of variables in the data set.
 TITLE6 lists the organization of the data set and is specified in a global macro variable by the user (%let
organization=One Record per Participant (ID);
VARIABLES SPECIFIED ON MACRO
The macro is called with the following syntax:
%proc_codebook(lib=libname,
file1=SAS_dataset,
fmtlib=work.formats,
pdffile=codebook_file.pdf
include_warn=NO);
Required Variables:
 LIB = name of library for SAS data set (see FILE1 variable) used to create the codebook
 FILE1 = name of SAS data set used to create the codebook
 FMTLIB = 2-level name of format library
 PDFFILE = name of PDF file for the codebook created
Optional Variables:
 INCLUDE_WARN= flag to control printing of WARNING messages in Codebook (in addition to printing
messages in LOG file):
o YES=prints warnings in file specified by PDFFILE (default),
o NO (or Any other text)=warnings printed only in LOG file.
3
Tips on embellishing your codebook
You can add a logo to the codebook by including a link to the logo as illustrated in the title1 statement in the
following example:
%let organization=One Record per ORGID*INJURY_DATE*INJURY_TYPE;
ods escapechar='~';
title1
j=c '~S={preimage="H:\datalys\Logo\datalys_color_logo_final.JPG"}';
title2 j=l "CODEBOOK: Women's Volleyball Injury Data Set 2004-05 to 2008-09";
footnote1 j=l 'SAS data set: injwvb0409.sas7bdat';
footnote2 j=l 'Created by H:\datalys\Chantala\Data Dec2009\injwvb0409.sas';
footnote3 'Listed Format assignment not always stored with permanent SAS data
set';
%proc_codebook(lib=work,
file1=injwvb0409,
fmtlib=work.formats,
pdffile=C:\My_project\injwvb0409_codebook.pdf,
include_warn=NO);
SAS Output:
4
You can also use ODS formatting options in the title statement to control the color, height or justification of text
in titles (http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000220968.htm). The
following code will center and use a font of 14pt for the main title of the codebook:
%let organization=One Record per ORGID*INJURY_DATE*INJURY_TYPE;
title j=center height=14pt "DATALYS PROJECT CODEBOOK: Women's Volleyball Injury
Data Set 2004-05 to 2008-09";
ods escapechar='~';
%proc_codebook(lib=work,
file1=injwvb0409,
fmtlib=work.formats,
pdffile= C:\My_project\injwvb0409_codebook \injwvb0409_codebook.pdf,
include_warn=NO);
run;
SAS Output:
You can also use text decorations in title statements to overline and underline text. For more information see
http://support.sas.com/rnd/base/new92/92pdf.html ).
5
Download