-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution 1.sas
86 lines (73 loc) · 1.64 KB
/
Solution 1.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
/*Import data from Excel sheets into SAS*/
filename reffile '/home/u63867400/sasuser.v94/Project 1/STAT.xlsx';
proc import datafile=reffile
dbms=xlsx
out=stat;
getnames=yes;
run;
filename reffile '/home/u63867400/sasuser.v94/Project 1/HIST.xlsx';
proc import datafile=reffile
dbms=xlsx
out=hist;
getnames=yes;
run;
filename reffile '/home/u63867400/sasuser.v94/Project 1/STUDHT.xlsx';
proc import datafile=reffile
dbms=xlsx
out=studht;
getnames=yes;
run;
/*Stack data from STAT and HIST*/
data stathist;
set stat hist;
run;
/*Merging STUDHT to STATHIST*/
proc sort data=stathist;
by name;
run;
proc sort data=studht;
by name;
run;
data statall;
merge stathist studht;
by name;
run;
/*Convert weight and height into metric system and calculate BMI and Categorize them*/
data statall1;
set statall;
weightkg=weight*.454;
heightmt=height*2.54/100;
bmi=weightkg/(heightmt*heightmt);
if bmi<18 then status='Underweight';
else if 18<=bmi<20 then status='Healthy';
else if 20<=bmi<22 then status='Overweight';
else if bmi>=22 then status='Obese';
run;
/*Generate pie chart for STATUS variable*/
proc chart data=statall1;
pie status;
run;
%macro myStat(var1,var2);
/*Create freq. dist. table */
proc freq data = statall1 noprint;
tables &var1*&var2 /out=myFreqTable;
run;
/*create report format*/
data myFreqTable1;
set myfreqtable;
value=cat(count,'(',round(percent,.01),'%)');
drop count percent;
run;
/*transposing variable*/
proc transpose data=myfreqtable1 out=t_myfreq;
by &var1;
id &var2;
var value;
run;
/*Create final report*/
title 'Report of Frequency Table';
proc print data=t_myfreq (drop=_name_);
run;
%mend;
%myStat(gender,status);
%myStat(status,gender);