Descibe a data set

Contents

proc contents data=sashelp.heart;
run;
SAS Connection established. Subprocess id is 4408
<!DOCTYPE html> SAS Output

The SAS System

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

The SAS System

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 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

The SGPlot Procedure

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

The SGPlot Procedure


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

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

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

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

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

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

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

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

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