标签:time stress work 变量 last nic 拼接 ssi concat
libname clinic ‘E:\sas‘; *one to one reading ; proc sort data=sasuser.admitjune out=work.adsort; by id; run; proc sort data=sasuser.stresstest out=work.stsort; by id; run; data work.one_to_one; set adsort(keep= id name sex age); set stsort(keep=timemin maxhr); run; proc print data=one_to_one; run; *concatenate; data concatenate(drop=resthr); set sasuser.stress98 sasuser.stress99; *直接拼接,行数=sum旧表行数 列数<=sum旧表列数, 变量名一样放一列( type一样,or error); if resthr < 72; run; proc print data=concatenate; run; *interleaving==cbind+sort; proc sort data=sasuser.stress98 out=work.s98; by tolerance; run; proc sort data=sasuser.stress99 out=work.s99; by tolerance; run; data work.interleave; set s98 s99; *拼表顺序:根据by先放第一个表中的单位(放完为止),根据by再放表2中的单位, 若表2无,回到表1,按by 的第二个值录入; by tolerance; run; proc print data=interleave; run; *match-merge; data work.merged; merge work.adsort work.stsort; * 旧表已sort ,跟据by,把ID相同的放在一起,列数=旧表列数和-重复变量名次数; by id; *note:merge在PDV中pointer的顺序; run; proc print data=work.merged; run; *当merge的两个数据集包含多个相同变量名时,(by只用一个),只能rename, 否则该变量内容被后面数据集的变量值重写; * (rename=(oldname=newname)); ; proc print data=sasuser.repertory; run; proc print data=sasuser.finance; run; proc print data=sasuser.company; run; data work.finrep; merge sasuser.repertory(rename=(date=daat2)) sasuser.finance (rename=(name=lastname)) sasuser.company; by ssn; run; run; proc print data=finrep; run; *去掉不是共有by后变量 单位; data work.merged2; /*merge有22个单位,merge有20个,去掉了ad和str的第一个单位miss和2458*/ merge work.adsort(in=ina) work.stsort(in=ins); by id; if ina and ins; *既不是0也不是missing,if判断为true是1或者nonmissing; run; *drop和keep变量时,注意他们是否在data步使用; data sasuser.merged; merge work.adsort (rename=(date=AdmitDate) in=inad drop=height weight) work.stsort (rename=(date=VisitDate) in=instr keep=id tolerance date); by id; if inad and instr; run; proc print data=sasuser.merged; run;
标签:time stress work 变量 last nic 拼接 ssi concat
原文地址:https://www.cnblogs.com/super-yb/p/11729548.html