title; OPTIONS FORMCHAR="|----|+|---+=|-/\<>*"; /*Read raw data from an infile*/ data march; infile "marflt.dat"; input flight 1-3 @4 date mmddyy6. @10 time time5. orig $ 15-17 dest $ 18-20 @21 miles comma5. mail 26-29 freight 30-33 boarded 34-36 transfer 37-39 nonrev 40-42 deplane 43-45 capacity 46-48; format date mmddyy10. time time5. miles comma5.; label flight="Flight number" orig ="Origination City" dest ="Destination City"; run; /*Import from Excel*/ PROC IMPORT OUT= WORK.MARCH DATAFILE= "MARCH.XLS" DBMS=EXCEL REPLACE; SHEET="march$"; GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; /*Read a .csv file*/ data pulse; infile "pulse.csv" firstobs=2 delimiter="," missover; input pulse1 pulse2 ran smokes sex height weight activity; run; /*Use Import Wizard for .csv file*/ PROC IMPORT OUT= WORK.pulse DATAFILE= "PULSE.CSV" DBMS=CSV REPLACE; GETNAMES=YES; DATAROW=2; RUN; /*Import an SPSS portable (.por) file*/ filename file1 "cars.por"; proc convert spss=file1 out=cars; run; /*Use Import Wizard to import an SPSS dataset (.sav) file*/ PROC IMPORT OUT= WORK.cars DATAFILE= "cars.sav" DBMS=SAV REPLACE; RUN; /*Read in a permanent SAS dataset*/ libname sasdata2 "C:\Documents and Settings\kwelch\Desktop\sasdata2"; data bank; set sasdata2.bank; run; /*Use a permanent SAS datset directly*/ libname sasdata2 "C:\Documents and Settings\kwelch\Desktop\sasdata2"; proc means data=sasdata2.bank; run; /*Another way to use a permanent SAS dataset*/ proc means data="C:\Documents and Settings\kwelch\Desktop\sasdata2\bank.sas7bdat"; run; /*Import a SAS transport file using Proc copy*/ libname trans xport "c:\Documents and Settings\kwelch\Desktop\sasdata2\owen.xpt"; proc copy in=trans out=sasdata2; run; /*Oneway frequencies*/ proc freq data=march; tables date dest ; run; /*Two-way cross-tabulations*/ proc freq data=pulse; tables sex*activity; run; /*Binomial test*/ proc freq data=pulse; tables smokes / binomial(p=.25); exact binomial; run; /*Chi-square goodness of fit test*/ proc freq data=pulse; tables activity / chisq testp=(.2,.5,.3); run; /*Chi-square test of independence*/ proc freq data=pulse; tables sex*smokes/chisq; run; /*McNemar's test for paired categorical data*/ data pulse2; set pulse; if pulse1 > 90 then hipulse1=1; if pulse1 <=90 and pulse1 not=. then hipulse1=0; if pulse2 > 90 then hipulse2=1; if pulse2 <=90 and pulse1 not=. then hipulse2=0; run; proc freq data=pulse2; tables hipulse1*hipulse2/ agree; run; /*Logistic Regression*/ proc logistic data=pulse2; class ran(ref="2") / param=ref; model hipulse2(event="1") = ran/ rsquare; run; /*Proc Means: Descriptive Stats*/ proc means data=pulse; run; /*Proc Means with a CLASS statement*/ proc means data=pulse; class ran; run; /*Proc Means with a BY statement--need to sort first*/ proc sort data=pulse; by ran; run; proc means data=pulse; by ran; run; /*Proc Univariate*/ proc univariate data=pulse; var pulse1; histogram; run; /*One-sample tests*/ proc univariate data=pulse mu0=62; var height; histogram; run; /*One-sample t-test*/ proc ttest data=pulse h0=62; var height; run; /*Independent samples t-test*/ proc ttest data=pulse; var pulse2; class ran; run; /*Wilcoxon test*/ proc npar1way data=pulse wilcoxon; var pulse2; class ran; run; /*Paired t-test*/ proc ttest data=pulse ; paired pulse2*pulse1; run; /*Oneway Anova*/ proc glm data=pulse; class activity; model pulse1=activity; means activity / tukey; run; quit; /*Kruskal-Wallis test*/ proc npar1way data=pulse wilcoxon; class activity; var pulse1; run; /*Linear regression*/ proc reg data=pulse; model pulse1 = height weight; run; quit; /*GLM ANCOVA model*/ proc glm data=pulse; class activity; model pulse1 = activity height weight; run; quit;