Descibe the data set

Contents

proc contents data=sashelp.heart;
run;
<!DOCTYPE html> SAS Output
Data Set Name SASHELP.HEART Observations 5209
Member Type DATA Variables 17
Engine V9 Indexes 0
Created 10/25/2018 02:21:26 Observation Length 168
Last Modified 10/25/2018 02:21:26 Deleted Observations 0
Protection   Compressed NO
Data Set Type   Sorted NO
Label Framingham Heart Study    
Data Representation SOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64    
Encoding us-ascii ASCII (ANSI)    
Engine/Host Dependent Information
Data Set Page Size 65536
Number of Data Set Pages 14
First Data Page 1
Max Obs per Page 389
Obs in First Data Page 365
Number of Data Set Repairs 0
Filename /opt/sasinside/SASHome/SASFoundation/9.4/sashelp/heart.sas7bdat
Release Created 9.0401M6
Host Created Linux
Inode Number 6235
Access Permission rw-r–r–
Owner Name sas
File Size 960KB
File Size (bytes) 983040
Alphabetic List of Variables and Attributes
# Variable Type Len Label
12 AgeAtDeath Num 8 Age at Death
5 AgeAtStart Num 8 Age at Start
3 AgeCHDdiag Num 8 Age CHD Diagnosed
15 BP_Status Char 7 Blood Pressure Status
14 Chol_Status Char 10 Cholesterol Status
13 Cholesterol Num 8  
2 DeathCause Char 26 Cause of Death
8 Diastolic Num 8  
6 Height Num 8  
10 MRW Num 8 Metropolitan Relative Weight
4 Sex Char 6  
11 Smoking Num 8  
17 Smoking_Status Char 17 Smoking Status
1 Status Char 5  
9 Systolic Num 8  
7 Weight Num 8  
16 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
Obs Status DeathCause AgeCHDdiag Sex AgeAtStart Height Weight Diastolic Systolic MRW Smoking AgeAtDeath Cholesterol Chol_Status BP_Status Weight_Status Smoking_Status
1 Dead Other . Female 29 62.50 140 78 124 121 0 55 .   Normal Overweight Non-smoker
2 Dead Cancer . Female 41 59.75 194 92 144 183 0 57 181 Desirable High Overweight Non-smoker
3 Alive   . Female 57 62.25 132 90 170 114 10 . 250 High High Overweight Moderate (6-15)
4 Alive   . Female 39 65.75 158 80 128 123 0 . 242 High Normal Overweight Non-smoker
5 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