Descibe a data set
Contents
proc contents data=sashelp.heart;
run;
<!DOCTYPE html>
SAS Output
|
SASHELP.HEART
|
5209
|
|
DATA
|
17
|
|
V9
|
0
|
|
10/25/2018 02:21:26
|
168
|
|
10/25/2018 02:21:26
|
0
|
|
|
NO
|
|
|
NO
|
|
Framingham Heart Study
|
|
|
SOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64
|
|
|
us-ascii ASCII (ANSI)
|
|
|
65536
|
|
14
|
|
1
|
|
389
|
|
365
|
|
0
|
|
/opt/sasinside/SASHome/SASFoundation/9.4/sashelp/heart.sas7bdat
|
|
9.0401M6
|
|
Linux
|
|
6235
|
|
rw-r–r–
|
|
sas
|
|
960KB
|
|
983040
|
|
AgeAtDeath
|
Num
|
8
|
Age at Death
|
|
AgeAtStart
|
Num
|
8
|
Age at Start
|
|
AgeCHDdiag
|
Num
|
8
|
Age CHD Diagnosed
|
|
BP_Status
|
Char
|
7
|
Blood Pressure Status
|
|
Chol_Status
|
Char
|
10
|
Cholesterol Status
|
|
Cholesterol
|
Num
|
8
|
|
|
DeathCause
|
Char
|
26
|
Cause of Death
|
|
Diastolic
|
Num
|
8
|
|
|
Height
|
Num
|
8
|
|
|
MRW
|
Num
|
8
|
Metropolitan Relative Weight
|
|
Sex
|
Char
|
6
|
|
|
Smoking
|
Num
|
8
|
|
|
Smoking_Status
|
Char
|
17
|
Smoking Status
|
|
Status
|
Char
|
5
|
|
|
Systolic
|
Num
|
8
|
|
|
Weight
|
Num
|
8
|
|
|
Weight_Status
|
Char
|
11
|
Weight Status
|
First few rows of the data set
proc print data=sashelp.heart (obs=5);
run;
<!DOCTYPE html>
SAS Output
|
Dead
|
Other
|
.
|
Female
|
29
|
62.50
|
140
|
78
|
124
|
121
|
0
|
55
|
.
|
|
Normal
|
Overweight
|
Non-smoker
|
|
Dead
|
Cancer
|
.
|
Female
|
41
|
59.75
|
194
|
92
|
144
|
183
|
0
|
57
|
181
|
Desirable
|
High
|
Overweight
|
Non-smoker
|
|
Alive
|
|
.
|
Female
|
57
|
62.25
|
132
|
90
|
170
|
114
|
10
|
.
|
250
|
High
|
High
|
Overweight
|
Moderate (6-15)
|
|
Alive
|
|
.
|
Female
|
39
|
65.75
|
158
|
80
|
128
|
123
|
0
|
.
|
242
|
High
|
Normal
|
Overweight
|
Non-smoker
|
|
Alive
|
|
.
|
Male
|
42
|
66.00
|
156
|
76
|
110
|
116
|
20
|
.
|
281
|
High
|
Optimal
|
Overweight
|
Heavy (16-25)
|
Cluster bars for categorical variables
ods graphics/noborder;
ods layout start rows=1 columns=2;
ods region row=1 column=1;
proc sgplot data=sashelp.heart;
vbar status/ group=bp_status groupdisplay=cluster;
yaxis grid;
title "Distribution (count) of survival status by bp_status";
run;
title;
ods region row=1 column=2;
proc sgplot data=sashelp.heart;
vbar status/ group=bp_status stat=percent groupdisplay=cluster;
yaxis grid;
title "Distribution (percent) of survival status by bp_status";
run;
title;
ods layout end;
<!DOCTYPE html>
SAS Output
Options
options mcompilenote=ALL symbolgen mprint;
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
232 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
232! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
233
234 options mcompilenote=ALL symbolgen mprint;
235
236 ods html5 (id=saspy_internal) close;ods listing;
237
Compile the macro
%macro cluster_barplot(lib=sashelp, dfn=heart, xgroup=status, ygroup=bp_status);
ods graphics on/noborder;
ods layout start rows=1 columns=2;
ods region row=1 column=1;
proc sgplot data=&lib..&dfn;
vbar &xgroup/ group=&ygroup groupdisplay=cluster;
yaxis grid;
title "Distribution (count) of %upcase(&xgroup) by %upcase(&ygroup) from data set %upcase(&lib..&dfn)";
run;
title;
ods region row=1 column=2;
proc sgplot data=&lib..&dfn;
vbar &xgroup/ group=&ygroup stat=percent groupdisplay=cluster;
yaxis grid;
title "Distribution (percent) of %upcase(&xgroup) by %upcase(&ygroup) from data set %upcase(&lib..&dfn)";
run;
title;
ods layout end;
ods graphics off;
%mend;
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
239 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
239! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
240
241 %macro cluster_barplot(lib=sashelp, dfn=heart, xgroup=status, ygroup=bp_status);
242
243 ods graphics on/noborder;
244
245 ods layout start rows=1 columns=2;
246
247
248 ods region row=1 column=1;
249 proc sgplot data=&lib..&dfn;
250 vbar &xgroup/ group=&ygroup groupdisplay=cluster;
251 yaxis grid;
252 title "Distribution (count) of %upcase(&xgroup) by %upcase(&ygroup) from data set %upcase(&lib..&dfn)";
253 run;
254 title;
255
256 ods region row=1 column=2;
257 proc sgplot data=&lib..&dfn;
258 vbar &xgroup/ group=&ygroup stat=percent groupdisplay=cluster;
259 yaxis grid;
260 title "Distribution (percent) of %upcase(&xgroup) by %upcase(&ygroup) from data set %upcase(&lib..&dfn)";
261 run;
262 title;
263
264
265 ods layout end;
266
267 ods graphics off;
268
269 %mend;
NOTE: The macro CLUSTER_BARPLOT completed compilation without errors.
19 instructions 1048 bytes.
270
271 ods html5 (id=saspy_internal) close;ods listing;
272
Call the macro with default parameters
%cluster_barplot()
<!DOCTYPE html>
SAS Output
Call the macro on another set of variables
%cluster_barplot(lib=sashelp, dfn=heart, xgroup=status, ygroup=chol_status)
<!DOCTYPE html>
SAS Output
Call the macro on another data set
%cluster_barplot(lib=sashelp, dfn=cars, xgroup=origin, ygroup=type)
<!DOCTYPE html>
SAS Output