PROC TABULATE is convenient for simple tables, so I wanted to post the code and the reference from SAS's support site. This article was simple enough for me to quickly construct a useful table.
Here is an example using my own data:
/* The example below illustrates a very simple table */
/* First the dataset */
data test;
input age_grp $ census_region $ income $ beta_only ;
datalines;
65-74 South low 1
65-74 South medium 0
85+ South low 0
65-74 South high 1
85+ West low 0
75-84 South medium 0
85+ South low 0
75-84 South high 0
85+ South low 0
85+ Midwest low 0
65-74 Midwest medium 0
65-74 West high 0
65-74 South low 0
75-84 West low 1
75-84 South low 0
85+ Midwest medium 0
75-84 South low 0
75-84 West low 1
75-84 Northeast medium 0
75-84 Northeast low 1
75-84 South medium 0
75-84 Northeast medium 1
75-84 South medium 1
75-84 Midwest medium 1
75-84 West medium 1
85+ South medium 1
65-74 West high 1
75-84 Midwest low 1
75-84 Midwest medium 0
75-84 South low 0
85+ Midwest medium 0
75-84 West low 0
75-84 South low 0
65-74 Northeast medium 1
85+ Midwest medium 0
65-74 South medium 1
75-84 Northeast medium 0
85+ Northeast medium 1
65-74 South high 0
65-74 West medium 0
85+ Midwest high 0
;
run;
/* Set up variables and a title */
%let my_cvars = age_grp census_region income;
%let trt = beta_only; /* Indicator for treatment */
title "Characteristics by treatment status for &trt";
/* Simple table */
proc tabulate data=test;
/* List categorical variables in a class statement */
class &trt &my_cvars;
/* Use keylabel to construct labels for proc tabulate tags */
keylabel n = 'N' all='Total' pctn='%' colpctn= 'Col %' rowpctn='Row %' ;
/* Define the table as: table rows, columns; */
table (&my_cvars all)
,
&trt*(n*f=comma6. pctn*f=comma6.1 colpctn*f=7.1 rowpctn*f=7.1)
;
run;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment