/********************************************** This example shows how to import an Excel File, set up missing value codes and create a permanent SAS data set. It also shows boxplots, two-sample t-tests, paired t-tests and one-sample t-tests. Filename: ttest.sas **********************************************/ PROC IMPORT OUT= WORK.owen DATAFILE= "d:\510\2007\data\Owen.xls" DBMS=EXCEL2000 REPLACE; GETNAMES=YES; RUN; libname b510 "d:\510\"; data b510.owen; set owen; if vit_a = 99 then vit_a = .; if head_cir = 99 then head_cir = .; if fatfold = 99 then fatfold = .; if b_weight = 999 then b_weight= .; if mot_age = 99 then mot_age = .; if b_order = 99 then b_order = .; if m_height = 999 then m_height=.; if f_height = 999 then f_height=.; bwt_g = b_weight*10; if bwt_g not=. and bwt_g < 2500 then lowbwt=1; if bwt_g >=2500 then lowbwt=0; log_fatfold = log(fatfold); htdiff = f_height - m_height; run; /*Boxplots of continuous variables by SEX. Data set must first be sorted BY SEX*/ proc sort data=b510.owen; by sex; run; proc boxplot data=b510.owen; plot bwt_g*sex / boxstyle=schematic; plot weight*sex / boxstyle=schematic; plot fatfold*sex / boxstyle=schematic; plot log_fatfold*sex / boxstyle=schematic; run; /*Descriptive Statistics for each level of SEX using a CLASS statement No sorting is necessary.*/ proc means data=b510.owen; class sex; var bwt_g weight fatfold log_fatfold; run; /*Descriptive Statistics for each level of SEX using a BY statement Data set must first be sorted BY SEX.*/ proc sort data=b510.owen; by sex; run; proc means data=b510.owen; by sex; var bwt_g weight fatfold log_fatfold; run; /*Independent Samples t-test comparing means of continous variables for each level of SEX. No sorting is necessary*/ proc ttest data=b510.owen; class sex; var bwt_g weight log_fatfold; run; /*Paired samples t-test comparing mother's height and father's height*/ proc ttest data=b510.owen; paired f_height*m_height; run; /*Paired samples t-test comparing mother's height and father's height for each level of SEX. Remember, data must be sorted BY SEX first. Because it was sorted earlier, we do not have to sort again.*/ proc ttest data=b510.owen; by sex; paired f_height*m_height; run; /*One-sample t-test to test whether mean of htdiff=0, using Proc ttest*/ proc ttest data=b510.owen; var htdiff; run; /*One-sample t-test to test whether mean of htdiff=0, using Proc Univariate*/ proc univariate data=b510.owen plot normal; var htdiff; histogram; run;