计算每个变量= 1的每个变量的数量

时间:2012-06-07 16:08:56

标签: sas

你能帮助计算每个变量= 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

1 个答案:

答案 0 :(得分: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,如果奇数则为空。 然后,只计算非缺失值(PROC MEANS中的N统计量)。