📄 ive_examples_editor.sas
字号:
/* iveware examples - sas editor mode */
/* import the sas datasets */
libname import xport "ive_examples_datain.exp";
proc copy in=import out=work;
run;
libname import xport "ive_examples_dataout.exp";
proc copy in=import out=work;
run;
/* simple design-based statistical description */
%describe(name=describe, dir=., setup=new);
title Simple design-based statistical description;
datain mydata1;
estout desexam1;
stratum stratum;
cluster psu;
weight fnlwgt2;
model mult;
mean age84 height weight;
contrast sex;
run;
/* multiple imputation */
%impute(name=impute, dir=., setup=new);
title Multiple imputation;
datain mydata2;
dataout impexam;
default continuous;
categorical casecnt gender race3 hyper diab smoke fammi edusubj3
cholesth;
mixed cafftot alcohol3;
transfer studyid;
restrict
numcig(smoke=2,3)
yrssmoke(smoke=2,3);
bounds
numcig(>0)
yrssmoke(>0,<=age-12)
fatindex(>0)
cafftot(>=0)
alcohol3(>=0);
maxpred
redtot(3)
wgtkg(2);
minrsqd .01;
iterations 5;
multiples 5;
seed 2001;
run;
/* simple jackknife regression */
%regress(name=regress, dir=., setup=new);
title Simple jackknife regression;
datain mydata1;
estout regexam1;
weight fnlwgt2;
stratum stratum;
cluster ppsu;
mdata skip;
link linear;
categorical health;
dependent dv12;
predictor age84 educ sex health;
estimates
agex: intercpt(1) age84(1) /
educ: intercpt(1) educ(1) /
health1: intercpt(1) health(1) /
health2: intercpt(1) health(0 1) /
health3: intercpt(1) health(0 0 1) /
health4: intercpt(1) health(0 0 0 1);
run;
/* multiply imputed design-based statistical description */
%describe(name=impute_describe, dir=., setup=new);
title Multiply imputed design-based statistical description;
datain mydata1;
mdata impute;
* impute keywords;
default transfer;
continuous age84 height weight;
categorical sex;
iterations 10;
multiples 5;
seed 100;
* describe keywords;
estout desexam2;
stratum stratum;
cluster psu;
weight fnlwgt2;
model mult;
mean age84 height weight;
contrast sex;
run;
/* multiply imputed jackknife regression */
/* recode the data to be multiply imputed */
data temp;
set mydata3;
if OWNBUYR=. then OWNBUYR=5;
if MORTGAGE=. then MORTGAGE=4;
if OWNBUYR=5 then AMTOWED=0;
if OWNBUYR=5 then PRESVAL=0;
OWN=0;
if OWNBUYR in(1,2) then OWN=1;
if OWNBUYR=.D then OWN=.;
BLACK=0;
if RACER=2 then BLACK=1;
OTHER=0;
if RACER=3 then OTHER=1;
LOGADL=log(NUMADL+1);
DIFFADL=log(NUMADL2R+1)-LOGADL;
LOGFLMR=log(NUMFLMR+1);
LOGIDL2R=log(NUMIDL2R+1);
LOGIADL=log(NUMIADL1+1);
LOGBD12=log(BDDAY12+1);
LOGDV12=log(DV12+1);
LOGAMTO=log(AMTOWED+1);
LOGPRES=log(PRESVAL+1);
run;
/* impute the missing data, extract the first imputed dataset */
%impute(name=impute_mult1, dir=., setup=new);
datain temp;
dataout mult1;
default categorical;
transfer respond numadl numadl2r numflmr numiadl1 numidl2r bdday12
dv12 amtowed presval racer ownbuyr;
continuous diffadl logadl educ age84 logflmr logidl2r logiadl
logbd12 logdv12 logamto logpres;
restrict
logamto(mortgage=2),
logpres(own=1);
bounds
logadl(>=0),
logflmr(>=0),
logidl2r(>=0),
logiadl(>=0),
logbd12(>=0),
logdv12(>=0),
logpres(> 0),
logamto(> 0);
iterations 5;
multiples 5;
seed 71901;
run;
/* extract the remaining four multiply imputed datasets */
%putdata(name=impute_mult1, dir=., mult=2, dataout=mult2);
%putdata(name=impute_mult1, dir=., mult=3, dataout=mult3);
%putdata(name=impute_mult1, dir=., mult=4, dataout=mult4);
%putdata(name=impute_mult1, dir=., mult=5, dataout=mult5);
/* analyze the imputed datasets */
%regress(name=impute_regress, dir=., setup=new);
title Multiply imputed jackknife regression;
datain
mult1
mult2
mult3
mult4
mult5;
estout regexam2;
dependent diffadl;
predictor poverty own educ logadl age84 sex black other;
run;
/* multiply imputed jackknife catmod */
%sasmod(name=sasmod, dir=., setup=new);
title Sasmod with Catmod;
datain
impute1
impute2
impute3
impute4
impute5;
estout modexam;
cluster psuvar;
stratum strvar;
weight wtvar;
* sas statements begin here;
proc catmod;
direct poverty female nonwhite;
model health=poverty female nonwhite;
run;
/* compare actual results to expected results */
proc compare base=descomp1 comp=desexam1 method=relative;
run;
proc compare base=impcomp comp=impexam method=relative;
run;
proc compare base=regcomp1 comp=regexam1 method=relative;
run;
proc compare base=descomp2 comp=desexam2 method=relative;
run;
proc compare base=regcomp2 comp=regexam2 method=relative;
run;
proc compare base=modcomp comp=modexam method=relative;
run;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -