-1

你能帮助计算每个变量=1的每个变量的数量吗?我在这里发布了如何计算丢失的数字。希望这是类似的方式。提前致谢。

/*y00*/
%let list0=OCALZHMR OCARTERY OCARTH  OCCHD OCDIABTS OCHBP OCMENTAL OCMYOCAR
          OCOTHART OCPSYCH OCSTROKE;

/*y01 and y02*/
%let list1=D_CFAIL D_CHD D_HBP D_MYOCAR D_OTHHRT  D_PSYCH D_RHYTHM D_STROKE 
       D_VALVE OCALZHMR OCARTERY OCARTH  OCCHD OCDIABTS OCHBP OCMENTAL OCMYOCAR 
       OCOTHART  OCPSYCH OCSTROKE;


proc means data=cohort00 nmiss noprint;
     var &list0; 
     output out=y2000_nmiss(drop=_:) nmiss= ;
run;

proc means data=cohort01 nmiss noprint;
     var &list1; 
     output out=y2001_nmiss(drop=_:) nmiss= ;
run;

data y2000_nmiss;
 set y2000_nmiss;
 j=1;
run;

data y2001_nmiss;
 set y2001_nmiss;
 j=1;
run;

proc transpose data=y2000_nmiss out=long0(rename=(COL1=Y2000 _name_=VAR));
     by j;
run;
proc transpose data=y2001_nmiss out=long1(rename=(COL1=Y2001 _name_=VAR));
     by j;
run;

data ATC_missing;
  merge long0 long1;
  by VAR;
  drop j;
run;

这是丢失数量的输出表的一部分:

   VARS  Y2000   Y2001  Y2002
OCDIABTS    0     1        0
OCHBP       0     0        0
OCMENTAL   17    18       10
OCMYOCAR    0     0        0
OCOTHART    0     0     4758
OCOTHHRT    .     .        .
OCPSYCH     0     0        0
4

1 回答 1

0
%let list1=Width Length Depth;

data work.is_even / view=work.is_even;
set sashelp.lake;
   array vars {*} &list1 ;
   drop i;
   do i=1 to dim(vars);
       if mod(round(vars(i), 1),2)  = 0 /* would be VARS(I)=1 for your case */
        then vars(i)=1;
   else vars(i)=.;
   end;
run;

proc means data=work.is_even n;
run;

首先,我创建了一个 datastep 视图 work.is_even(查看以避免数据的完整副本),它以我需要的方式操作数据。在这里,如果舍入值是偶数,它将覆盖变量的原始值(不在原始数据中,只是在该视图中)1,如果是奇数,则覆盖 null。然后,只计算非缺失值(PROC MEANS 中的 N 统计量)。

于 2012-06-08T08:19:32.813 回答