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)
Horizontal box plot for a continuous variable
ods graphics on/noborder;
proc sgplot data=sashelp.heart;
hbox weight;
title "Boxplot for variable %sysfunc(upcase(weight)) from data set %sysfunc(upcase(sashelp.heart))";
run;
title;
ods graphics off;
<!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 ”>
114 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods 114! graphics on / outputfmt=png; NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT 115 116 options mcompilenote=ALL symbolgen mprint; 117 118 ods html5 (id=saspy_internal) close;ods listing; 119
Data driven horizontal box plots
Compile the macro
%macro hbox(lib=sashelp, df=heart);
%let dfn=%scan(&lib..&df, -1);
data &dfn;
set &lib..&df;
keep _numeric_;
run;
%let dfn=%upcase(&dfn);
data _null_;
set sashelp.vcolumn end=final;
where libname="WORK" and memname="&dfn";
call symputx('col'||left(_n_), name);
if final then call symputx('totalcol', _n_);
run;
%do i=1 %to &totalcol;
ods graphics on/noborder;
proc sgplot data=&dfn;
hbox &&col&i;
title "Boxplot for %upcase(&&col&i) from data set %upcase(&lib..&dfn)";
run;
title;
ods graphics off;
%end;
%mend ;
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd ”>
182 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods 182! graphics on / outputfmt=png; NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT 183 184 %macro hbox(lib=sashelp, df=heart); 185 186 187 %let dfn=%scan(&lib..&df, -1); 188 189 data &dfn; 190 191 set &lib..&df; 192 193 keep _numeric_; 194 run; 195 196 197 %let dfn=%upcase(&dfn); 198 199 200 data _null_; 201 202 set sashelp.vcolumn end=final; 203 204 where libname="WORK" and memname="&dfn"; 205 206 call symputx('col'||left(_n_), name); 207 208 if final then call symputx('totalcol', _n_); 209 210 run; 211 212 %do i=1 %to &totalcol; 213 214 ods graphics on/noborder; 215 216 proc sgplot data=&dfn; 217 218 hbox &&col&i; 219 220 title "Boxplot for %upcase(&&col&i) from data set %upcase(&lib..&dfn)"; 221 222 run; 223 224 title; 225 226 ods graphics off; 227 228 %end; 229 230 231 %mend ; NOTE: The macro HBOX completed compilation without errors. 33 instructions 1216 bytes. 232 233 ods html5 (id=saspy_internal) close;ods listing; 234
Call the default macro
%hbox()
<!DOCTYPE html>
SAS Output
svgtitle
The SGPlot Procedure 30 40 50 60 Age at Start Boxplot for AGEATSTART from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 50 55 60 65 70 75 Height Boxplot for HEIGHT from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 100 150 200 250 300 Weight Boxplot for WEIGHT from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 50 75 100 125 150 Diastolic Boxplot for DIASTOLIC from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 100 150 200 250 300 Systolic Boxplot for SYSTOLIC from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 100 150 200 250 Metropolitan Relative Weight Boxplot for MRW from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 0 10 20 30 40 50 60 Smoking Boxplot for SMOKING from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 40 60 80 Age at Death Boxplot for AGEATDEATH from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 100 200 300 400 500 Cholesterol Boxplot for CHOLESTEROL from data set SASHELP.HEART The SGPlot Procedure