SAS常用语句

导入xls格式数据

PROC IMPORT OUT= WORK.dat
            DATAFILE= "\FILENAME" 
            DBMS=EXCEL REPLACE;
     RANGE="Sheet1$"; 
     GETNAMES=YES;
     MIXED=NO;
     SCANTEXT=YES;
     USEDATE=YES;
     SCANTIME=YES;
RUN;

字符型变量(VA)转换为数值型(A)

DATA VA;
SET A;
VA=A*1;
RUN;

自定义输出小数位数

ODS output Slices=res1; 

/*increase the decimal places and view*/
proc print data=res1 label; 
      format    FValue 8.5
           ProbF 19.15; 
      var _numeric_;
      title "Parameter Estimates";
run;

清空所有

dm ' log;clear;odsresult;clear; output; clear; ';

正态性检验

proc univariate data= normal;
class group;
Var ;
run;

卡方检验

proc freq data=dat;
tables group*gender/chisq nopercent nocol expected;
run;

Means 程序

proc sort data=a ;
by group;
proc means data=  mean std max min maxdec=3;
by group;
var;
run;

/*上下四分位数*/
proc means data=dat median Q1 Q3 max min maxdec=3;
class group;
var   height weight BMI;
run;

t检验

proc ttest data=dat;
   class group;
   var  ;
run;

SORT排序

proc sort data=dat; 
by group;
run;

FDR校正

data fdra;
   input Raw_P @@;
   datalines;
0.0011
.0001
0.7223
.0001
0.7059
.0001
.0001
.0001
.0001
0.0408
0.5641
0.0059
0.0186
0.2144
0.0022
;
proc multtest inpvalues=fdra holm hoc fdr;
run;

方差齐性检验

Means group/hovtest;

筛选并输出保存数据

data  A B C;
set dat;
    if block='A' then output A;
      if block='B' then output B;
        if block='C' then output C;
run;

标准化数据

PROC STANDARD DATA=DAT MEAN=0 STD=1 OUT=zDAT;
  VAR  ;
RUN;

Glimmix适用于非正态分布数据

/*glimmix for any distribution*/
 proc GLIMMIX data=dat;
 class block group ID;
   model reaction_time = group block block*group/ solution ddfm=kr;
   random intercept ID;
  lsmeans block*group/slice=block pdiff ADJUST=bon;
run;


注:ddfm=kr 为 Kenward-Roger method

mixed程序

proc mixed data=dat method=type3;
   class block group ID;
   model mean_score = block GROUP group*block/ddfm=kr s ;
   random ID;
   lsmeans group*block/slice=block CL ADJUST=bon;
run;

GLM方差分析并检验残差正态性

/*anova */
proc glm data= ;
 class group;
 model percent = GROUP/p;output out=r R=RES;
 means GROUP / snk;
 run;
 quit;
 /*test residuals normal*/
 proc univariate data=r normal;var res;run;
quit;

查看变量类型

proc contents data= dat1;
run;

    发表回复

    您的电子邮箱地址不会被公开。 必填项已用 * 标注