/********************************************** 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= "C:\temp\labdata\Owen.xls" DBMS=EXCEL2000 REPLACE; GETNAMES=YES; RUN; libname labdata "c:\temp\labdata\"; data labdata.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*/ proc sort data=labdata.owen; by sex; run; proc boxplot data=labdata.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*/ proc means data=labdata.owen; class sex; var bwt_g weight fatfold log_fatfold; run; proc means data=labdata.owen; by sex; var bwt_g weight fatfold log_fatfold; run; /*Independent Samples t-test comparing means of continous variables by sex*/ proc ttest data=labdata.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=labdata.owen; paired f_height*m_height; run; proc ttest data=labdata.owen; by sex; paired f_height*m_height; run; /*One-sample t-test to test whether mean of htdiff=0*/ proc univariate data=labdata.owen plot normal; var htdiff; histogram; run;