Descibe a data set
Contents
proc contents data=sashelp.heart;
run;
SAS Connection established. Subprocess id is 4408
<!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 and normal density curvers for a continuous variable
ods graphics on/noborder;
proc sgplot data=sashelp.heart;
histogram weight / scale=count;
density weight / type=normal;
density weight / type=kernel;
title "Histogram, normal density and kernel density plots for %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 ”>
50 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods 50 ! graphics on / outputfmt=png; NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT 51 52 options mcompilenote=ALL symbolgen mprint; 53 54 ods html5 (id=saspy_internal) close;ods listing; 55
Compile a macro for creating histograms, normal density and kernel density plots
%macro hist(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=work.&dfn;
histogram &&col&i / scale=count;
density &&col&i / type=normal;
density &&col&i / type=kernel;
title "Histogram, normal density and kernel density plots 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 ”>
121 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods 121! graphics on / outputfmt=png; NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT 122 123 %macro hist(lib=sashelp, df=heart); 124 125 126 %let dfn=%scan(&lib..&df, -1); 127 128 data &dfn; 129 130 set &lib..&df; 131 132 keep _numeric_; 133 run; 134 135 136 %let dfn=%upcase(&dfn); 137 138 139 data _null_; 140 141 set sashelp.vcolumn end=final; 142 143 where libname="WORK" and memname="&dfn"; 144 145 call symputx('col'||left(_n_), name); 146 147 if final then call symputx('totalcol', _n_); 148 149 run; 150 151 %do i=1 %to &totalcol; 152 153 ods graphics on/noborder; 154 155 proc sgplot data=work.&dfn; 156 157 histogram &&col&i / scale=count; 158 159 density &&col&i / type=normal; 160 161 density &&col&i / type=kernel; 162 163 title "Histogram, normal density and kernel density plots for %upcase(&&col&i) from data set %upcase(&lib..&dfn)"; 164 165 run; 166 167 title; 168 169 ods graphics off; 170 171 %end; 172 173 %mend ; NOTE: The macro HIST completed compilation without errors. 35 instructions 1464 bytes. 174 175 ods html5 (id=saspy_internal) close;ods listing; 176
Call the macro with default parameters
%hist()
<!DOCTYPE html>
SAS Output
svgtitle
The SGPlot Procedure 20 30 40 50 60 70 Age at Start 0 100 200 300 400 Count Kernel Normal Histogram, normal density and kernel density plots for AGEATSTART from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 50 60 70 80 Height 0 100 200 300 400 500 600 Count Kernel Normal Histogram, normal density and kernel density plots for HEIGHT from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 50 100 150 200 250 300 Weight 0 200 400 600 800 Count Kernel Normal Histogram, normal density and kernel density plots for WEIGHT from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 50 75 100 125 150 Diastolic 0 200 400 600 800 1000 1200 Count Kernel Normal Histogram, normal density and kernel density plots for DIASTOLIC from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 100 150 200 250 300 Systolic 0 200 400 600 800 Count Kernel Normal Histogram, normal density and kernel density plots for SYSTOLIC from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 50 100 150 200 250 Metropolitan Relative Weight 0 200 400 600 800 1000 Count Kernel Normal Histogram, normal density and kernel density plots for MRW from data set SASHELP. HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure -20 0 20 40 60 Smoking 0 500 1000 1500 2000 2500 Count Kernel Normal Histogram, normal density and kernel density plots for SMOKING from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 40 60 80 100 Age at Death 0 50 100 150 200 Count Kernel Normal Histogram, normal density and kernel density plots for AGEATDEATH from data set SASHELP.HEART The SGPlot Procedure
svgtitle
The SGPlot Procedure 100 200 300 400 500 600 Cholesterol 0 200 400 600 800 1000 Count Kernel Normal Histogram, normal density and kernel density plots for CHOLESTEROL from data set SASHELP.HEART The SGPlot Procedure