Descibe the 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)
|
Histogram, kernel density curve, normal density curve and box plot for a continuous variable (i.e., weight)
ods graphics on/noborder;
ods noproctitle;
ods layout Start rows=1 columns=3;
ods region row=1 column=1;
proc sgplot data=sashelp.heart;
histogram weight / scale=count;
density weight / type=normal;
density weight / type=kernel;
title "Histogram for variable %sysfunc(upcase(weight)) from data set %sysfunc(upcase(sashelp.heart))";
run;
title;
ods region row=1 column=2;
proc univariate data=sashelp.heart;
ods select qqplot;
var weight;
qqplot weight / normal(mu=est sigma=est);
*title "Qq plot for variable %sysfunc(upcase(weight)) from data set %sysfunc(upcase(sashelp.heart))";
run;
title;
ods region row=1 column=3;
proc sgplot data=sashelp.heart;
hbox weight;
title "Box plot for variable %sysfunc(upcase(weight)) from data set %sysfunc(upcase(sashelp.heart))";
run;
title;
ods layout end;
ods graphics off;
<!DOCTYPE html>
SAS Output
Compile the macro
%macro plot_contvar(lib=sashelp, dfn=heart, contvar=weight);
ods graphics on/noborder;
ods noproctitle;
ods layout Start rows=1 columns=3;
ods region row=1 column=1;
proc sgplot data=&lib..&dfn;
histogram &contvar / scale=count;
density &contvar / type=normal;
density &contvar / type=kernel;
title "Histogram for %upcase(&contvar) from data set %upcase(&lib..&dfn)";
run;
title;
ods region row=1 column=2;
proc univariate data=&lib..&dfn;
ods select qqplot;
var &contvar;
qqplot &contvar / normal(mu=est sigma=est);
**title "QQ plot for %upcase(&contvar) from data set %upcase(&lib..&dfn)";
run;
title;
ods region row=1 column=3;
proc sgplot data=&lib..&dfn;
hbox &contvar;
title "Boxplot for %upcase(&contvar) 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”>
206 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
206! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
207
208 %macro plot_contvar(lib=sashelp, dfn=heart, contvar=weight);
209
210 ods graphics on/noborder;
211
212 ods noproctitle;
213
214 ods layout Start rows=1 columns=3;
215
216 ods region row=1 column=1;
217 proc sgplot data=&lib..&dfn;
218 histogram &contvar / scale=count;
219 density &contvar / type=normal;
220 density &contvar / type=kernel;
221 title "Histogram for %upcase(&contvar) from data set %upcase(&lib..&dfn)";
222 run;
223 title;
224
225
226 ods region row=1 column=2;
227 proc univariate data=&lib..&dfn;
228 ods select qqplot;
229 var &contvar;
230 qqplot &contvar / normal(mu=est sigma=est);
231 **title "QQ plot for %upcase(&contvar) from data set %upcase(&lib..&dfn)";
232 run;
233 title;
234
235
236 ods region row=1 column=3;
237 proc sgplot data=&lib..&dfn;
238 hbox &contvar;
239 title "Boxplot for %upcase(&contvar) from data set %upcase(&lib..&dfn)";
240 run;
241 title;
242
243
244 ods layout end;
245
246 ods graphics off;
247
248 %mend ;
249
250 ods html5 (id=saspy_internal) close;ods listing;
251
Call the default macro
%plot_contvar()
<!DOCTYPE html>
SAS Output
Call the macro on another continuous varible (i.e., diastolic)
%plot_contvar(lib=sashelp, dfn=heart, contvar=diastolic)
<!DOCTYPE html>
SAS Output
Call the macro on another continuous variable (i.e., systolic)
%plot_contvar(lib=sashelp, dfn=heart, contvar=systolic)
<!DOCTYPE html>
SAS Output