资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,畜禽场育种,数,数据统计分,析,析SAS应用初,步,步王楚端,郑,郑江霞,一,、,、SAS,系,系,统,统,简,简,介,介,SAS,(,(StatisticalAnalysisSystem,),)是,当,当,前,前,使,使,用,用,最,最,为,为,广,广,泛,泛,的,的统,计,计,分,分,析,析,软,软,件,件YSTAT,),)之,一,一,;,;,1966,年,年,美,美,国,国NorthCarolina,州,州,立,立,大,大,学,学,开,开,始,始,开,开,发,发,目,目,前,前,国,国,际,际,上,上,最,最,流,流,行,行,的,的,一,一,种,种大,型,型,统,统,计,计,分,分,析,析,系,系,统,统,统,统,计,计,分,分,析,析,的,的标,准,准,软,软,件,件,其,其,基,基,本,本,部,部,分,分,是,是SAS/BASE软,件,件,,,,,在,在,此,此,基,基,础,础,上,上,可,可,根,根,据,据,需,需,要,要,加,加,上,上SAS,系,系,统,统,的,的,其,其,他,他,模,模,块,块,SAS/STAT,(,(,统,统,计,计,分,分,析,析,),);SAS/ETS,(,(,经,经,济,济,预,预,测,测,或,或,时,时,间,间,序,序,列,列,分,分,析,析,),),;,;SAS/QC,(,(,质,质,量,量,控,控,制,制,管,管,理,理,),),;,;SAS/OR,(,(,运,运,筹,筹,学,学,),),;,;SAS/IML,(,(,矩,矩,阵,阵,运,运,算,算,),),;,;SAS/GRAPH,(,(,绘,绘,图,图,),),等,等,信,信,息,息,存,存,储,储,简,简,单,单,(,(,能,能,读,读,取,取,任,任,何,何,形,形,式,式,的,的,数,数,据,据,),),语,语,言,言,编,编,程,程,能,能,力,力,强,强,对,对,数,数,据,据,连,连,续,续,处,处,理,理,统,统,计,计,分,分,析,析,方,方,法,法,丰,丰,富,富,,,,,使,使,用,用,简,简,单,单,SAS,过,过,程,程,傻,傻,瓜,瓜,系,系,统,统,SAS,系,系,统,统,的,的,组,组,成,成,系,统,统,管,管,理,理,程,序,序,功,能,能,程,程,序,序,库,SAS/BASE-,SAS/STAT,SAS/GRAPH,SAS/QC,SAS/OR,SAS/ETS,SAS/IML,SAS/ASSIST,SAS,系,系,统,统,二,、,、SAS,系,系,统,统,的,的,启,启,动,动,与,与,关,关,闭,闭,(,一,一,),),启,启,动,动在WINDOWS,操,操,作,作,系,系,统,统,中,中,,,,,直,直,接,接,用,用,鼠,鼠,标,标,双,双,击,击,桌,桌,面,面,上,上SAS,系,系,统,统,的,的,快,快,捷,捷,键,键,图,图,标,标,,,,,即,即,进,进,入,入SAS,系,系,统,统,。,。,SAS,系,系,统,统,软,软,件,件,有,有,时,时,间,间,租,租,期,期,限,限,制,制,,,,,因,因,此,此,只,只,有,有,机,机,器,器,时,时,间,间,在,在,软,软,件,件,有,有,效,效,期,期,内,内,才,才,能,能,运,运,行,行,OUTPUT(SAS,结,结,果,果,输,输,出,出,窗,窗,口,口,),),LOG(SAS,日,日,志,志,窗,窗,口,口,,,,,随,随,着,着SAS,语,语,句,句,的,的,执,执,行,行,,,,,显,显,示,示,出,出SAS,系,系,统,统,的,的,信,信,息,息,和,和,已,已,执,执,行,行,的,的,语,语,句,句,),),PGM(SAS,程,程,序,序,编,编,辑,辑,窗,窗,口,口,),),(,二,二,),),退,退,出,出,安,装,装,:,:,农,农,大,大,资,资,源,源,仅,仅,供,供,学,学,习,习,启,动,动,file,edit,view,tools,solutions,window,help,退,出,出,四,、,、SAS,程,程,序,序,结,结,构,构,(,一,一,),),程,程,序,序,结,结,构,构,在SAS,系,系,统,统,中,中,任,任,何,何,一,一,个,个,完,完,整,整,的,的,处,处,理,理,过,过,程,程,均,均,可,可,分,分,为,为,两,两,大,大,步,步,数,据,据,步,步,和,和,过,过,程,程,步,步,数,据,据,步,步,将,将,不,不,同,同,来,来,源,源,的,的,数,数,据,据,读,读,入,入SAS,系,系,统,统,建,建,立,立,起,起SAS,数,数,据,据,集,集,。,。,由,由DATA,语,语,句,句开,始,始,,,,,以,以RUN语,句,句,结,结,束,束,。,。,数,据,据,可,可,以,以,由,由,外,外,部,部,或,或,过,过,程,程,读,读,入,入,;,;,或,或,者,者由CARDS,语,语,句,句开,始,始,,,,直,接,接,输,输,入,入,数,数,据,据,,数,数,据,据,输,输,入,入,完,完,后,后,提,提,行,行,单,单,独,独,加,加,“,“;”,结,结,束,束,简,单,单,运,运,行,行,样,样,例,例,假,设,设,我,我,们,们,有,有,一,一,个,个,班,班,学,学,生,生,的,的,数,数,学,学,成,成,绩,绩,和,和,语,语,文,文,成,成,绩,绩,,,,,数,数,学,学,满,满,分,分,为,为100,,,,,语,语,文,文,满,满,分,分,为,为120,,,,,希,希,望,望,计,计,算,算,学,学,生,生,的,的,平,平,均,均,分,分,数,数,(,(,按,按,百,百,分,分,制,制,),),并,并,按,按,此,此,排,排,名,名,,,,,可,可,以,以,在,在,程,程,序,序,窗,窗,口,口,输,输,入,入,此,此,程,程,序,序,:,:,title0401,班,班,学,学,生,生,成,成,绩,绩,排,排,名,名;,datac0401;,inputname$sex$mathchinese;,avg=math*0.5+chinese/120*100*0.5;,cards;,李,明,明,男,男9298,张,红,红,艺,艺,女,女89106,王,思,思,明,明,男,男8690,张,聪,聪,男,男98109,刘,颍,颍,女,女80110,;,run;,procprint;run;,procsortdata=c0401;,bydescendingavg;,run;,procprint;run;,如,果,果,数,数,据,据,要,要,永,永,久,久,保,保,存,存,libname,ad:SAS82SAS82SASMYWORK;,/*mywork,子,子,目,目,录,录,已,已,事,事,先,先,存,存,在,在*/,data,a.aaaa;,inputx;,cards;,12345,;,procprint,;,varx;,run,;,过,程,程,步,步,调,调,用,用SAS,系,系,统,统,中,中,已,已,编,编,好,好,的,的,各,各,种,种,过,过,程,程,来,来,处,处,理,理,和,和,分,分,析,析,数,数,据,据,集,集,中,中,的,的,数,数,据,据,。,。,每,每,一,一,个,个,过,过,程,程,步,步,均,均,以,以PROC,语,语,句,句开,始,始,,,,RUN,语,语,句,句,结,结,束,束,,,,,并,并,且,且,每,每,个,个,语,语,句,句,后,后,均,均,以,以,“,“;,”,”,结,结,束,束,。,。,(,二,二,),),程,程,序,序,的,的,输,输,入,入,、,、,修,修,改,改,调,调,试,试,和,和,运,运,行,行,SAS,程,程,序,序,只,只,能,能,在,在PGM,窗,窗,口,口,输,输,入,入,、,、,修,修,改,改,,,,,可,可,在,在,各,各,行,行,的,的,任,任,何,何,位,位,置,置,开,开,始,始SAS,语,语,句,句,的,的,书,书,写,写,。,。,一,一,个,个,语,语,句,句,可,可,以,以,连,连,续,续,写,写,在,在,几,几,行,行,中,中,,,,,一,一,行,行,中,中,也,也,可,可,以,以,同,同,时,时,写,写,上,上,几,几,个,个,语,语,句,句,,,,,但,但,每,每,个,个,语,语,句,句,后,后,面,面,必,必,须,须,用,用,“,“,;,;,”,”,隔,隔,开,开,。,。,当,一,一,个,个,程,程,序,序,输,输,入,入,完,完,后,后,,,,,发,发,送,送,程,程,序,序,的,的,命,命,令,令,为,为F10,功,功,能,能,键,键,或,或SUBMIT,。,。,当,当,程,程,序,序,发,发,送,送,到,到SAS,系,系,统,统,后,后,,,,PGM,的,的,程,程,序,序,语,语,句,句,全,全,部,部,自,自,动,动,清,清,除,除,,,,LOG,窗,窗,口,口,将,将,逐,逐,步,步,记,记,下,下,程,程,序,序,运,运,行,行,的,的,过,过,程,程,和,和,出,出,现,现,的,的,错,错,误,误,信,信,息,息,(,(,用,用,红,红,色,色,提,提,示,示,错,错,误,误,),),。,。,如,如,果,果,过,过,程,程,步,步,没,没,有,有,错,错,误,误,,运,运,行,行,完,完,成,成,后,后,,,,,通,通,常,常,会,会,在,在OUTPUT,窗,窗,口,口,打,打,印,印,出,出,结,结,果,果,如,如,果,果,程,程,序,序,运,运,行,行,出,出,错,错,,,,则,需,需,要,要,在,在PGM,窗,窗,口,口,用,用RECALL,(,(,或,或F9,),),命,命,令,令,调,调,回,回,已,已,发,发,送,送,的,的,程,程,序,序,进,进,行,行,修,修,改,改,。,。,保存SAS程,序,序及,其,其他,窗,窗口,内,内容,激活,相,相应,窗,窗口,,,,然,后,后选,择,择:,方式,一,一:,鼠,鼠标,点,点击,“,“存,盘,盘”,工,工具,按,按钮,方式,二,二:,执,执行,菜,菜单,命,命令,【,【File】,【Save,】,】/,【,【Saveas,】,】,可保,存,存程,序,序、,数,数据,文,文件,、,、运,行,行结,果,果、,日,日志,等,等。,SAS保,存,存成,纯,纯文,本,本格,式,式文,件,件。,打开,已,已保,存,存的,文,文件,只能,在,在ProgramEdit窗,口,口打,开,开文,件,件,,选,选择,:,:,方式,一,一:,鼠,鼠标,点,点击,“,“打,开,开”,工,工具,按,按钮,方式,二,二:,执,执行,菜,菜单,命,命令,【,【File】,【Open,】,】,可打,开,开以,前,前保,存,存的,程,程序,、,、数,据,据文,件,件、,运,运行,结,结果,、,、日,志,志等,文,文件,及,及其,他,他文,本,本格,式,式的,文,文件,。,。,对于,定,定量,资,资料,的,的统,计,计描,述,述和,简,简单,推,推断,,,,SAS,提,提供,了,了三,个,个强,有,有力,的,的程,序,序步,,,,它,们,们是,:,:,MEANS过,程,程,提,提供,单,单个,或,或多,个,个变,量,量的,简,简单,描,描述,,,,对,于,于多,个,个变,量,量,,它,它的,输,输出,格,格式,紧,紧凑,,,,便,于,于阅,读,读。,UNIVARIATE,过,过程,提,提,供,供单,个,个变,量,量的,详,详细,描,描述,和,和对,其,其分,布,布类,型,型的,检,检验,。,。,TTEST过,程,程,对,对变,量,量进,行,行t/u,检,检验,。,。,四、,定量,资,资料,的,的统,计,计描,述,述和t检,验,验,PROCMEANS,选,选择,项,项,计算,描,描述,统,统计,量,量的MEANS,过,过程,VAR 变量表,BY 变量表,CLASS 变量,WEIGHT 变量,OUTPUT 选择项,FREQ 变量,1.N13.STDERR,2.NMISS14.T,3.MEAN15.PRT,4.STD16.SUMWGT,5.MIN17.SKEWNESS,6.MAX18.KURTOSIS,7.RANGE,8.SUM,9.VAR,10.USS,11.CSS,12.CV,PROCUNIVARIATE,选,选,择,择,项,项,描,述,述,统,统,计,计,量,量,的,的UNIVARIATE,过,过,程,程,VAR 变量表,BY 变量表,FREQ 变量,WEIGHT 变量,OUTPUT OUT=,1.DATA=SAS,数,数,据,据,集,集,2.PLOT,做,茎,茎,叶,叶,图,图,、,、,盒,盒,式,式,图,图,、,、,正,正,态,态,概,概,率,率,图,图,3.FREQ,做,频,频,数,数,分,分,布,布,表,表,4.,进,行,行,正,正,态,态,性,性,检,检,验,验,/*LT3*/,DATAA;,INPUTYIELD;,CARDS;,17721519797123159245119119131149152,16710416121412517521911819217617595,136199116165214951588313780138151,1871261961342061379897129143179174,159194136108101141148168163176102158,14517375130149150161155111205131189,91142140154152163123187149155131209,18397119181149254131215111186118150,155197116184239160172179151198124179,135151168169173181188211197175122159,171166175143190213192231163159158159,177147 194227141 169124165,;,PROC MEANS MEANSTD CV STDERRMAXDEC=2;,PROC CHART;,VARYIELD;,PROC FREQ;,PROC UNIVARIATENORMAL PLOT;,RUN;,数值保,留,留两位,小,小数,t,检验,1、,样本平,均,均数与,总,总体平,均,均数的,差,差异显,著,著性检,验,验,DATAA;,INPUTy;,y=y-4.50;,cards;,4.33 4.623.894.14 4.784.644.52 4.484.554.26,;,PROC MEANSN MEANSTDERR TPRT;,RUN;,程序说,明,明:样本平,均,均数与,总,总体平,均,均数的,差,差异显,著,著性检,验,验可调,用,用MEANS过程。,DATA语句产生临,时,时数据,集,集A,,表,表明数,据,据步的,开,开始;,INPUT语,句,句指明读,取,取变量,y,,表示读,入,入一条,观,观测值,后,后不换,行,行,连,续,续读入,数,数据,,减,减少数,据,据输入,行,行;,CARDS语,句,句表明以,下,下为数,据,据行,,数,数据行,下,下的“,;,;”表,示,示数据,行,行结束,;,;,PROC MEANS语句指,明,明调用MEANS过,程,程对数,据,据集A,进,进行分,析,析,输,出,出样本,含,含量N,、,、平均,数,数MEAN、,平,平均数,的,的标准,误,误STDERR、学,生,生氏T,值,值和,t,值概率PRT,;,;,RUN,语,语句表示过,程,程步结,束,束,开,始,始运行,过,过程步,。,。,2、,配对试,验,验资料,的,的,t,检验,DATAB;,INPUTIDx1x2;,d=x1-x2;,CARDS;,137.837.9,238.239.0,338.038.9,437.638.4,537.937.9,638.139.0,738.239.5,837.538.6,938.538.8,1037.939.0,;,PROC MEANSMEAN STDERRT PRT;,VARd;,RUN;,3、,非配对,试,试验资,料,料的,t,检验,DATAC;,INPUTbreedy;,CARDS;,15728911202 361101282,113725011192 391117232,11042571732 82153296,1682311118,;,PROC TTEST;,CLASSbreed;,VARy;,RUN;,五、方,差,差分析,固定模,型,型,随机模,型,型,混合模,型,型,常用的,方,方差分,析,析模型,表,表达,主效应,模,模型,Y=ABC,互作效,应,应模型,Y=ABCA*BA*CB*CA*B*C,嵌套效,应,应模型,Y=AB (A),3、方,差,差分析SAS,过,过程,对于一,般,般的方,差,差分析,(,(平衡,资,资料,,即,即各处,理,理重复,数,数相等,),)可用ANOVA过程;,对,对于非,平,平衡资,料,料(各,处,处理重,复,复数不,等,等)的,方,方差分,析,析可用GLM过程。,ANOVA过程调,用,用格式,PROC ANOVA ;,CLASS,效,效应名,;,;,MODEL,因,因变量,名,名=效,应,应名;,MEANS,效,效应列,表,表/选,项,项;,LSD,最,最小,显,显著差,数,数法,SNK,最,最小,显,显著极,差,差法,DUNCN,邓,邓肯氏,均,均数比,较,较检验,T 两,两,两T检,验,验,ALPHA=0.05 检,验,验显著,水,水平,GLM过程调,用,用格式,PROC GLM,;,;,CLASS,效,效应名,;,;,MODEL,因,因变量,名,名=效,应,应名;,MEANS,效,效应表/选项;,LSMEANS 效,应,应表/,选,选项;,RANDOM,;,;,STDERR,最,最小,二,二乘均,数,数标准,误,误,TDIFF最,小,小二乘,均,均数差,异,异显著,性,性检验,单因素,试,试验(,各,各处理,重,重复数,相,相等),DATA E;,INPUTTR$y;,cards;,A115A116A115A117A118,A245A242A250A238A239,A330A335A329A331A335,A431A428A420A425A430,A540A535A531A532A530,;,PROC anova;CLASSTR;,modely=TR;,MEANSTR/T;,RUN;,ClassLevelsValues,TR5A1A2A3A4A5,Numberofobservations25,DependentVariable: y,Sumof,SourceDFSquaresMeanSquareF ValuePr F,Model41905.440000476.36000034.32 F,TR41905.440000476.36000034.32F,Model446.4983333311.624583335.990.0025,Error2038.841666671.94208333,CorrectedTotal2485.34000000,R-SquareCoeffVarRootMSEyMean,0.5448607.5656161.39358718.42000,SourceDFTypeI SSMean SquareF Value Pr F,BREED446.4983333311.624583335.99 0.0025,SourceDFTypeIII SSMean SquareF Value Pr F,BREED446.4983333311.624583335.99 0.0025,Comparisonssignificantatthe0.05levelareindicated by *.Difference,BREEDBetween95% Confidence,ComparisonMeansLimits,B1-B40.5417-1.33482.4181,B1-B31.86670.10643.6269*,B1-B23.00001.32174.6783*,B1-B53.54171.66525.4181*,B4-B1-0.5417-2.41811.3348,B4-B31.3250-0.62513.2751,B4-B22.45830.58194.3348*,B4-B53.00000.94455.0555*,B3-B1-1.8667-3.6269-0.1064*,B3-B4-1.3250-3.27510.6251,B3-B21.1333-0.62692.8936,B3-B51.6750-0.27513.6251,B2-B1-3.0000-4.6783-1.3217*,B2-B4-2.4583-4.3348-0.5819*,B2-B3-1.1333-2.89360.6269,B2-B50.5417-1.33482.4181,B5-B1-3.5417-5.4181-1.6652*,B5-B4-3.0000-5.0555-0.9445*,B5-B3-1.6750-3.62510.2751,B5-B2-0.5417-2.41811.3348,DATA F;,INPUTA$B$y;,cards;,A1B13.5A1B22.3 A1 B3 2.0,A2B12.6A2B22.0 A2 B3 1.9,A3B12.0A3B21.5 A3 B3 1.2,A4B11.4A4B20.8 A4 B3 0.3,;,PROC ANOVA;,CLASSA B;,modely=AB;,MEANSA B/DUNCAN;,RUN;,3.,两,两因素,交,交叉分,组,组单独,观,观察值,Class LevelInformation,ClassLevels Values,A4A1A2 A3 A4,B3B1B2 B3,Dependent Variable:y,Sumof,SourceDFSquares MeanSquare FValue Pr F,Model57.510833331.5021666734.89 0.0002,Error60.258333330.04305556,Corrected Total117.76916667,R-SquareCoeffVarRoot MSEy Mean,0.96674911.581300.2074981.791667,SourceDFAnova SS MeanSquare FValue Pr F,A35.289166671.7630555640.95 0.0002,B22.221666671.1108333325.80 0.0011,DuncansMultiple RangeTestfory,NOTE: This testcontrolstheType Icomparisonwise errorrate, not the experimentwise errorrate.,Means with the sameletter are not significantlydifferent.,Duncan GroupingMeanNA,A2.60003 A1,B2.16673 A2,C1.56673 A3,D0.83333A4,Duncan GroupingMeanNB,A2.37504B1,B1.65004B2,B,B1.35004B3,六、相关,分,分析,PROCCORR 选,项,项;,VAR,变,变量名;,WITH,变,变量,名,名;,PARTIAL,变,变量名表,;,;,(PEARSON),SPEARMAN,NOSIMPLE,指明偏相,关,关变量(,即,即保持固,定,定的变量,),),不能,出,出现在VAR,和,和WITH 语句,中,中。,DATAG;,INPUT,xy,;,CARDS;,80235086 24009827209025001203150,102268095263083240011330801052920,1102960 1002860,;,PROCCORR;,RUN;,TheCORRProcedure,2 Variables: xy,Simple Statistics,variableNMeanStdDevSumMinimumMaximum,x1298.5000012.37666 118280.00000120.00000,y122721274.936633265023503150,PearsonCorrelationCoefficients, N= 12,Prob |r| underH0:Rho=0,Xy,x1.000000.97740,.0001,y0.977401.00000,F,Model1794340794340213.81|t|,Intercept1582.18497147.315333.950.0027,x121.712171.4848814.62.0001,实习:,1、将讲,过,过的所有,程,程序重复,运,运行一次,。,。,2、完成,下,下面数据,的,的分析。,a1 b1 c10.7069a1 b1 c10.7854a1 b1 c10.3581,a1 b1 c20.0785a1 b1 c20.1885a1 b1 c20.3408,a1 b2 c11.0838a1 b2 c10.9425a1 b2 c10.3335,a1 b2 c20.5027a1 b2 c20.9550a1 b2 c20.9215,a2 b1 c10.0628a2 b1 c10.0942a2 b1 c10.0471,a2 b1 c20.0126a2 b1 c20.0126a2 b1 c20.0094,a2 b2 c10.4712a2 b2 c10.0880a2 b2 c10.1759,a2 b2 c20.2246a2 b2 c20.2513a2 b2 c20.3676,a 年龄,组,组b 体重,组,组 c,性,性别组,指标:血,清,清IgG,含,含量,要求用3因素GLM过程,分,分析,比较各年,龄,龄组的差,别,别,
展开阅读全文