Docsity

SAS Data Analysis: Creating Permanent Data Set and Generating Descriptive Statistics - Pro, Assignments of Biostatistics

Toggle sidebar
bg1
Biostat 510
Homework 2
KEY 100 pts total
Due Thursday, January 18, 2007
/*Question 1: Re-import the Excel Files from the First Homework*/
PROC IMPORT OUT= WORK.group1
DATAFILE= "C:\Documents and Settings\kwelch\Desktop\510\homework\homework1\
group1.xls"
DBMS=EXCEL REPLACE;
SHEET="Sheet1$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
OPTIONS FORMCHAR="|----|+|---+=|-/\<>*";
libname b510 "C:\Documents and Settings\kwelch\Desktop\510\";
/*Question 2: Create the permanent SAS data set b510.allgroups*/
/*Question 3: Create new variables in your permanent data set
To do this, rerun the data step commands.*/
data b510.allgroups;
set group1
group2
group3
group4
group5
group6
group7
group8;
if age = 999 then age = .;
if height = 999 then height = .;
if weight = 999 then weight = .;
if num_sibs = -1 then num_sibs=.;
if distance = -1 then distance = . ;
if weight = 999 then weight = . ;
if pulse1 = 999 then pulse1 = .;
if pulse2 = 999 then pulse2 = .;
if sex = "m" then sex = "M";
if sex = "f" then sex = "F";
pulsediff = pulse2 - pulse1;
bmi = (weight * .454)/((height*2.54)/100)**2 ;
run;
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download SAS Data Analysis: Creating Permanent Data Set and Generating Descriptive Statistics - Pro and more Assignments Biostatistics in PDF only on Docsity!

Biostat 510

Homework 2

KEY 100 pts total

Due Thursday, January 18, 2007

/Question 1: Re-import the Excel Files from the First Homework/

PROC IMPORT OUT= WORK.group

DATAFILE= "C:\Documents and Settings\kwelch\Desktop\510\homework\homework1\

group1.xls"

DBMS=EXCEL REPLACE;

SHEET="Sheet1$";

GETNAMES=YES;

MIXED=NO;

SCANTEXT=YES;

USEDATE=YES;

SCANTIME=YES;

RUN;

OPTIONS FORMCHAR="|----|+|---+=|-/&lt;>*";

libname b510 "C:\Documents and Settings\kwelch\Desktop\510";

/Question 2: Create the permanent SAS data set b510.allgroups/

/*Question 3: Create new variables in your permanent data set

To do this, rerun the data step commands.*/

data b510.allgroups;

set group

group

group

group

group

group

group

group8;

if age = 999 then age = .;

if height = 999 then height = .;

if weight = 999 then weight = .;

if num_sibs = -1 then num_sibs=.;

if distance = -1 then distance =. ;

if weight = 999 then weight =. ;

if pulse1 = 999 then pulse1 = .;

if pulse2 = 999 then pulse2 = .;

if sex = "m" then sex = "M";

if sex = "f" then sex = "F";

pulsediff = pulse2 - pulse1;

bmi = (weight * .454)/((height2.54)/100)*2 ;

run;

/*Question 4: Describe the continuous variables

AGE, PULSE1, PULSE2, PULSEDIFF

and get a histogram for each*/

proc univariate data=b510.allgroups;

var AGE PULSE1 PULSE2 PULSEDIFF;

histogram;

run;

/*Question 5: Get descriptive statistics for all numeric variables in your

new data set for those who RAN and for those who did not run*/

proc sort data=b510.allgroups;

by ran;

run;

proc means data=b510.allgroups ;

by ran;

run;

/OR...No sorting necessary when using a Class Statement/

proc means data=b510.allgroups;

class ran;

run;

/*Question 6: Side-by-Side Boxplots by RAN

Note: the sorting must be done before the boxplots can be made, but because the

data are already sorted, this step is not necessary*/

proc sort data=b510.allgroups;

by ran;

run;

proc boxplot data=b510.allgroups;

plot (Pulse1 Pulse2 Pulsediff) * ran / boxstyle=schematic;

run;

/*Question 7: Side-by-Side Boxplots by SEX

Note: the sorting must be done before the boxplots can be made, but because the

data are already sorted, this step is not necessary*/

proc sort data=b510.allgroups;

by sex;

run;

proc boxplot data=b510.allgroups;

plot (AGE BMI) * sex / boxstyle=schematic;

run;

/Question 8: ScatterPlots/

proc plot data=b510.allgroups;

plot pulse2 * pulse1;

run; quit;

proc sort data=b510.allgroups;

by ran;

run;

proc plot data=b510.allgroups;

by ran;

plot pulse2 * pulse1;

run; quit;

1. Re-import the Excel files from homework 1, Group1.xls – Group8.xls. 2. (Included in the SAS Commands—no output) Combine the Excel files into one permanent SAS data set , called b510.allgroups. Remember that you have to set up a libname statement to define the library before you can save the permanent data set. Be sure you set up the libname statement so your data set will be saved in a location where you will be able to access it again later from another computer. Your IFS account is one place where you can store the files, or you can place them on a USB drive, or other removeable media. Make sure you set up the missing value codes correctly in the data step. After importing the Excel files, use commands similar to those shown below to save the permanent SAS data set:

/*Proc Import commands go before the data step

that combines the Excel files*/

libname b510 "d:\b510\2007";

data b510.allgroups;

set group

group

group

group

group

group

group

group8;

if distance = -1 then distance =. ;

if weight = 999 then weight =. ;

if sex = "m" then sex = "M";

if sex = "f" then sex = "F";

run;

Make sure you submit the libname statement before running the data step. You should see something like the following message in your SAS log, indicating that the data set was successfully created: 102 libname b510 "d:\510\2007"; NOTE: Libref B510 was successfully assigned as follows: Engine: V Physical Name: d:\510 103 data b510.allgroups; 104 set group 105 group 106 group 107 group 108 group 109 group 110 group 111 group8; 112 113 if distance = -1 then distance =. ; 114 if weight = 999 then weight =. ; 115 116 if sex = "m" then sex = "M"; 117 if sex = "f" then sex = "F"; 118 119 run; NOTE: There were 8 observations read from the data set WORK.GROUP1. NOTE: There were 8 observations read from the data set WORK.GROUP2.

NOTE: There were 9 observations read from the data set WORK.GROUP3. NOTE: There were 11 observations read from the data set WORK.GROUP4. NOTE: There were 13 observations read from the data set WORK.GROUP5. NOTE: There were 10 observations read from the data set WORK.GROUP6. NOTE: There were 10 observations read from the data set WORK.GROUP7. NOTE: There were 6 observations read from the data set WORK.GROUP8. NOTE: The data set B510.ALLGROUPS has 75 observations and 11 variables.

3. (Included in the SAS commands—no output) Create new variables in your permanent data set. a) PULSEDIFF, which is calculated by subtracting pulse1 from pulse2. b) BMI. BMI = Weight in kilograms / height in meters-squared Be sure that you convert height in inches to height in meters, and weight in kilograms to weight in pounds when you calculate bmi. The range of BMI values should be from about 15 to 35. The conversion formulas are: Height in centimeters = 2.54 times height in inches Height in meters = height in centimeters / 100 Weight in kilograms = 0.454 times weight in pounds Your commands to create the new variables will look something like those below. Remember, you need to add these commands to your data step commands, and resubmit them, so the data set will get recreated, and the new variables will be added to it.

pulsediff = pulse2 - pulse1;

bmi = (weight * .454)/((height2.54)/100)*2 ;

Be sure they add these commands to their data step. If they make a new data set, then you can subtract 2 points…its not wrong, but is inefficient.

4. (5 pts) Use Proc Univariate to get the distribution of AGE, PULSE1, PULSE2, PULSEDIFF, and BMI. Create a histogram for each of these continuous variables. Include the histograms in your homework assignment. Describe these distributions in terms of their skewness, and in terms of outliers.

--------------------------------------------- Ran=0 --------------------------------------------- The MEANS Procedure Variable Label N Mean Std Dev Minimum Maximum

Group Group 38 4.4736842 2.1275140 1.0000000 8. ID ID 38 5.6578947 2.9889555 1.0000000 12. Age Age 38 24.7105263 3.5098925 21.0000000 35. Height Height 38 66.6578947 3.3472564 62.0000000 74. Weight Weight 38 142.1842105 24.3941234 110.0000000 225. Num_sibs Num_sibs 38 1.6052632 1.3464563 0 6. Distance Distance 36 1694.94 3153.70 45.0000000 12000. Pulse1 Pulse1 38 73.2894737 10.1313212 53.0000000 99. Pulse2 Pulse2 38 73.2368421 10.2652239 49.0000000 100. pulsediff 38 -0.0526316 5.5114003 -13.0000000 16. bmi 38 22.4626155 2.9597176 17.6643415 33.

--------------------------------------------- Ran=1 --------------------------------------------- Variable Label N Mean Std Dev Minimum Maximum

Group Group 37 4.5405405 2.1420991 1.0000000 8. ID ID 37 5.1351351 3.1460925 1.0000000 13. Age Age 37 26.1081081 4.8636051 21.0000000 43. Height Height 37 67.0270270 3.7821693 62.0000000 75. Weight Weight 36 146.5833333 28.5560852 102.0000000 215. Num_sibs Num_sibs 37 1.6756757 1.4917189 0 7. Distance Distance 36 2886.04 4295.64 0.5000000 13000. Pulse1 Pulse1 37 76.4324324 9.3705820 58.0000000 102. Pulse2 Pulse2 37 98.7567568 20.4102444 71.0000000 162. pulsediff 37 22.3243243 16.9165502 3.0000000 83. bmi 36 22.8161514 3.1873262 18.0845411 34.

6. (5pts) Make a side-by-side boxplot of PULSE1, PULSE2, and PULSEDIFF using RAN as the X-axis variable. Include these three boxplots in your homework write-up. (You can resize them so they don’t take up much room). Don’t forget to sort by RAN before running the boxplots. How do these variables compare visually for those who ran and those who did not run? Discuss the boxplots in terms of central tendency (mean and median) and in terms of spread (the whiskers) and outliers for the two groups. Explain why these differ, if they do differ, and why they don’t differ if they do not differ (and remember, they can differ in the central tendency, spread, and/or outliers).

The distribution of Pulse1 looks similar for those who ran and those who did not run. They have similar spread. The Means and Medians appear to be about equal for this variable, and there appears to be at least one high outlier for this variable for those who ran and for those who did not run. The Mean of Pulse1 for those who ran is a slight bit higher than for those who did not run. The distribution of Pulse2 looks somewhat different for those who ran vs. those who did not run. The mean and median are similar for those who did not run, indicating that the distribution is fairly symmetric, but for those who ran, the mean is higher than the median, indicating that there is a skewed distribution for these folks. There also appear to be a couple of outliers at the high end of Pulse2 for those who ran, and one sort of outlier for those who did not run. The distribution of Pulsediff looks quite different for those who ran vs. those who did not run. The mean and median for those who did not run are approx. equal, indicating that the distribution is approximately symmetric. For those who ran, the mean is higher than the median, indicating that the distribution is skewed positively. There is also more variability in the distribution of Pulse2 for those who ran than for those who did not run. We expect this because some folks respond to running by having a bigger difference in pulse from time1 to time2 than others. There are also some high outliers for those who ran and both high and low outliers for those who did not run. Credit for this question should be based on them having the boxplots, and on a reasonable interpretation of the boxplots. I'd like them to mention both the central tendency shown in the boxplots and the variability.

7. (5pts) Make a side-by-side boxplot of AGE and of BMI using SEX as the X-axis variable. Include these two boxplots in your homework write-up. You will need to sort by SEX before you can run these boxplots. Discuss these boxplots in terms of central tendency, spread, and outliers for the two groups. Explain why you think these boxplots differ by SEX, if they do differ, or why they do not differ, if they do not.

Plot of Pulse2Pulse1. Legend: A = 1 obs, B = 2 obs, etc. | | 180 + | | | | A 160 + A | | | 140 +^ | | | | P | A A u 120 + A l s | (^) | A AA e | A AA 2 | A A 100 + A A A | AA A A A A A | A A A AA | | A B (^) A AA (^) AA B 80 + B AB A A | B D A | A AA A B AA A A A | A A A A 60 +^ |^ A A AA^ A A | A | | A | 40 + | ---+-------------+-------------+-------------+-------------+-------------+-------------+-- 50 60 70 80 90 100 110 --------------------------------------------- Ran=0 --------------------------------------------- Plot of Pulse2Pulse1. Legend: A = 1 obs, B = 2 obs, etc. 100 + A | | | A | | 90 + | | | A AA | A | AA 80 + A A | AA P |^ | BA u | A B A A l | A A A A A s 70 + A e | A 2 | A A A | | AA | A A A 60 + | A | A | | | 50 + | A | | | | 40 + ---+-------------+-------------+-------------+-------------+-------------+-- 50 60 70 80 90 100 Pulse --------------------------------------------- Ran=1 --------------------------------------------- Plot of Pulse2*Pulse1. Legend: A = 1 obs, B = 2 obs, etc. 180 + | | | | | A 160 + A | | | | | 140 + | |

P | u l || A A s 120 + A e | 2 | A A A | A | A A A 100 +^ |^ A A | A AA A A | A AA AA | A A | A A A A 80 +^ |^ AA | A | A A | A A | | 60 + ---+-------------+-------------+-------------+-------------+-------------+-------------+-- 50 60 70 80 90 100 110 Pulse

9. (25pts) Import the 8 new Excel files created in class on January 11, 2007. These will be on my web page, and will be called Group1A.xls , Group2A.xls , etc. Put these data sets together into one permanent data set, which you should call: b510.allgroupsA. Get a Proc Contents, simple descriptive statistics, and frequencies for the categorical variables in this new data set. The CONTENTS Procedure Data Set Name B510.ALLGROUPSA Observations 72 Member Type DATA Variables 8 Engine V9 Indexes 0 Created Friday, January 19, 2007 05:59:07 PM Observation Length 96 Last Modified Friday, January 19, 2007 05:59:07 PM Deleted Observations 0 Protection Compressed NO Data Set Type Sorted NO Label Variables in Creation Order

Variable Type Len Format Informat Label

1 undergrad Char 35 $35. $14. Undergrad 2 Group Num 8 Group 3 ID Num 8 ID 4 Eye Num 8 Eye 5 Car Num 8 Car 6 Miles_Car Num 8 Miles_Car 7 Eye_Color Char 5 $5. $5. Eye_Color 8 Hours_Ex Num 8 Hours_Ex The MEANS Procedure Variable Label N Mean Std Dev Minimum Maximum

Group Group 72 4.3055556 2.1795392 1.0000000 8. ID ID 71 5.7183099 3.3686924 1.0000000 13. Eye Eye 71 0.8169014 0.8160858 0 2. Car Car 71 0.8309859 0.3774318 0 1. Miles_Car Miles_Car 58 75469.62 50443.17 1600.00 233000. Hours_Ex Hours_Ex 70 3.8428571 3.1144158 0 20.

The FREQ Procedure Undergrad Cumulative Cumulative undergrad Frequency Percent Frequency Percent

ANTHROPOLOGY 1 1.41 1 1. Anthropology 3 4.23 4 5. BIOLOGY 1 1.41 5 7. BIOPSYCHOLOGY 1 1.41 6 8. BIology 1 1.41 7 9. BUSINESS 1 1.41 8 11. Biochemistry 2 2.82 10 14.

Frequency Missing = 1 Eye Cumulative Cumulative Eye Frequency Percent Frequency Percent

0 31 43.66 31 43. 1 22 30.99 53 74. 2 18 25.35 71 100. Frequency Missing = 1 Car Cumulative Cumulative Car Frequency Percent Frequency Percent

0 12 16.90 12 16. 1 59 83.10 71 100. Frequency Missing = 1 Eye_Color Cumulative Cumulative Eye_Color Frequency Percent Frequency Percent

BLUE 3 4.23 3 4. BROWN 11 15.49 14 19. Blue 15 21.13 29 40. Brown 24 33.80 53 74. GREEN 1 1.41 54 76. Gray 1 1.41 55 77. Green 6 8.45 61 85. HAZEL 2 2.82 63 88. Hazel 7 9.86 70 98. Mixed 1 1.41 71 100. Frequency Missing = 1

10. Save your commands before you exit SAS. It should be a command file called homework2.sas. Include a partial listing of homework2.sas with your homework. Check to make sure that your commands run without errors by submitting them all at once. If there are any errors, fix them and rerun your commands.