-
Notifications
You must be signed in to change notification settings - Fork 0
/
14 Summary Reports1.sas
416 lines (334 loc) · 7.73 KB
/
14 Summary Reports1.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/*01 Proc Freq*/
libname nhanes3 '/courses/d649d56dba27fe300/STA5066';
proc contents data=nhanes3.exam;
run;
proc freq data=nhanes3.exam nlevels;
tables seqn/noprint;
run;
proc contents data=nhanes3.Nhanes1_5066;
run;
proc freq data=nhanes3.nhanes1_5066;
tables activ;
run;
proc freq data=nhanes3.nhanes1_5066;
tables activ diabetic gender race smoking_status vital_status;
run;
proc freq data=nhanes3.nhanes1_5066;
tables activ diabetic gender
race smoking_status vital_status/nocum;
run;
proc freq data=nhanes3.nhanes1_5066;
tables sbp;
run;
proc freq data=nhanes3.nhanes1_5066 ;
tables activ / chisq plots=none;
run;
proc freq data=nhanes3.nhanes1_5066;
tables gender*activ;
run;
proc freq data=nhanes3.nhanes1_5066;
tables gender*activ/nocol nopercent;
run;
proc freq data=nhanes3.nhanes1_5066;
tables activ*gender/norow nopercent;
run;
proc freq data=nhanes3.nhanes1_5066;
tables age;
run;
proc format;
value agefmt low-39="<40"
40-49="40-49"
50-59="50-59"
60-high="60-69"
;
run;
proc freq data=nhanes3.nhanes1_5066;
tables age;
format age agefmt.;
run;
proc freq data=nhanes3.nhanes1_5066;
where gender="Male";
tables age*diabetic/nocol nopercent;
format age agefmt.;
run;
proc freq data=nhanes3.nhanes1_5066;
tables gender*activ/crosslist;
run;
proc freq data=nhanes3.nhanes1_5066;
tables gender*activ/crosslist norow nocol nopercent;
run;
proc freq data=nhanes3.nhanes1_5066;
where gender="Male";
tables age*diabetic/list;
format age agefmt.;
run;
proc freq data=nhanes3.nhanes1_5066;
tables diabetic*vital_status/
nocol nopercent chisq;
run;
proc freq data=nhanes3.nhanes1_5066;
tables race*diabetic*vital_status/
nocol nopercent chisq;
run;
proc freq data=nhanes3.nhanes1_5066;
tables race*gender*diabetic*vital_status/
nocol nopercent chisq;
run;
proc freq data=nhanes3.nhanes1_5066;
tables race*(diabetic activ)/
nocol nopercent chisq;
run;
proc freq data=nhanes3.nhanes1_5066;
tables (race diabetic)* activ/nocol nopercent chisq;
run;
proc freq data=nhanes3.nhanes1_5066;
tables (race diabetic)* (activ gender)/nocol nopercent chisq;
run;
data cigsdth;
do cigs=0 to 1;
do dth=0 to 1;
input number @@;
output;
end;
end;
datalines;
819 132 1498 333
;
run;
proc
print data=cigsdth;run;
proc freq data= cigsdth;
tables cigs*dth/nocol nopercent chisq;
weight number;
run;
/*02 Proc Means */
proc means data=nhanes3.nhanes1_5066;
run;
proc means data=nhanes3.nhanes1_5066;
var sbp bmi chol;
run;
proc means data=nhanes3.nhanes1_5066;
var sbp;
class Gender;
run;
proc means data=nhanes3.nhanes1_5066 median min max;
var bmi;
class gender;
run;
proc means data=nhanes3.nhanes1_5066 ;
var chol;
class gender;
run;
proc means data=nhanes3.nhanes1_5066 maxdec=1;
var chol;
class gender;
run;
libname orion '/courses/d649d56dba27fe300/STA5066';
proc means data=orion.sales;
var Salary;
class Country;
run;
proc means data=orion.sales nonobs;
var Salary;
class Country;
run;
proc means data=nhanes3.nhanes1_5066 noprint;
var sbp;
output out=means;
run;
proc print data=means;
run;
proc means data=nhanes3.nhanes1_5066 noprint;
var sbp;
class gender;
output out=means1;
run;
proc print data=means1;
run;
proc means data=nhanes3.nhanes1_5066 noprint;
var sbp;
class gender race;
output out=work.means2
min=minSbp max=maxSbp
sum=sumSbp mean=aveSbp;
run;
proc print data=means2;
run;
proc means data=orion.sales noprint nway;
var Salary;
class Gender Country;
output out=work.means2
min=minSalary max=maxSalary
sum=sumSalary mean=aveSalary;
run;
proc print data=work.means2;
run;
proc means data=orion.sales noprint descendtypes;
var Salary;
class Gender Country;
output out=work.means2
min=minSalary max=maxSalary
sum=sumSalary mean=aveSalary;
run;
proc print data=work.means2;
run;
proc contents data=orion.sales;run;
proc print data=orion.sales(obs=23);run;
proc freq data=orion.sales;
tables country;
run;
proc means data=orion.sales noprint;
var Salary;
class Gender Country;
output out=work.means mean=aveSalary;
run;
proc print data=means;
run;
title;
data gender_summary(keep=Gender aveSalary)
country_summary(keep=Country aveSalary);
set work.means;
if _type_=1 then output country_summary;
else if _type_=2 then output gender_summary;
run;
proc print data=gender_summary;
run;
proc print data=country_summary;
run;
proc sort data=orion.sales out=sort_country;
by Country;
run;
data detail_country;
merge sort_country
country_summary
(rename=(aveSalary=CountrySalary));
by Country;
run;
proc print data=detail_country (obs=10);
run;
proc sort data=detail_country out=sort_gender;
by Gender;
run;
data detail_country_gender;
merge sort_gender
gender_summary(rename=(aveSalary=GenderSalary));
by Gender;
if Salary>CountrySalary then CS='Above Average'; else CS='Below Average';
if Salary>GenderSalary then GS='Above Average'; else GS='Below Average';
label CS='Comparison*to Country*Salary Average'
GS='Comparison*to Gender*Salary Average';
run;
proc print data=detail_country_gender (obs=100);
run;
proc sort data=detail_country_gender;
by Employee_ID;
run;
proc print data=detail_country_gender split='*';
var First_Name Last_Name Salary CS GS;
run;
data normmns;
call streaminit(57131);/*seed*/
do rep=1 to 10000;
do n=1 to 9;
x=rand("normal");/*random standard normal*/
output;
end;
end;
run;
proc means data=normmns noprint mean;
by rep;
var x;
output out=means mean=mn_x;
run;
ods select histogram goodnessoffit;
proc univariate data=means;
var mn_x;
histogram mn_x/normal;
run;
/*03 Proc Univariate*/
/*create analytic data set*/
data nhanes1_a;
set nhanes3.nhanes1_5066;
id=_n_+100000;
run;
/*a basic call */
proc univariate data=nhanes1_a;
var sbp;
run;
/*the id statement*/
proc univariate data=nhanes1_a;
var sbp;
id id;
run;
/*add a histogram*/
proc univariate data=nhanes1_a;
var sbp;
histogram sbp;
run;
/*add an overlay of a normal and an inset--
see SAS help for list of parametric distributions*/
proc univariate data=nhanes1_a;
var sbp;
histogram sbp/normal;
inset mean(6.1) std(5.1) n /position=ne;
run;
/*a lognormal with inset statement*/
title 'Systolic Blood Pressure';
ods select ParameterEstimates GoodnessOfFit FitQuantiles histogram;
proc univariate data=nhanes1_a;
var sbp;
histogram / lognormal (theta=est) midpoints=80 to 280 by 10;
inset n mean(5.1) std='Std Dev' (4.1) skewness (5.3)
/ pos = ne header = 'Summary Statistics';
run;
title;
/*add a class statement, midpoints of histogram,
estimate an offset (theta)*/
title 'Systolic Blood Pressure';
ods select ParameterEstimates GoodnessOfFit FitQuantiles histogram;
proc univariate data=nhanes1_a;
class gender;
var sbp;
histogram / lognormal (theta=est) midpoints=80 to 280 by 10;
inset n mean(5.1) std='Std Dev' (4.1) skewness (5.3)
/ pos = ne header = 'Summary Statistics';
run;
title;
/*qqplots */
proc univariate data=nhanes1_a mu0=135;
var sbp;
qqplot sbp/normal ;
qqplot sbp/lognormal(sigma=est theta=est);
run;
/*cdf plots*/
proc univariate data=nhanes1_a mu0=135;
var sbp;
cdfplot sbp/normal ;
cdfplot sbp/lognormal(sigma=est theta=est);
run;
/*non parametric density estimation*/
proc univariate data=nhanes1_a mu0=135;
var sbp;
histogram sbp/kernel;
run;
/*parametric and non parametric density estimation*/
proc univariate data=nhanes1_a mu0=135;
var sbp;
histogram sbp/lognormal kernel;
run;
/*create a data set with frequencies
quick intro to PROC SQL*/
proc sql;
create table sbpfreqs as
select sbp, count(*) as num
from nhanes1_a
group by sbp
;
select * from sbpfreqs
;
quit;
/* the freq statement*/
proc univariate data=sbpfreqs;
var sbp;
freq num;
run;