Descibe a data set

Contents

proc contents data=sashelp.heart;
run;
<!DOCTYPE html> SAS Output

The CONTENTS Procedure

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)

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