全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
16771 9
2014-12-02
请教各位大神,如何统计每个变量的缺失值,有270多个变量,50000多个观测,现在想要统计每个变量的缺失情况,也就是每一列的缺失情况,缺失值有.和空格两种,大部分都是character变量,少部分数值型,只要统计缺失和不缺失两种情况即可,万分感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-12-2 10:10:24
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value  missfmt  . ='Missing' other='Not Missing';
run;

proc freq data=yourdata;
format _CHAR_ $missfmt.;
tables _CHAR_ / missing missprint nocum nopercent;
format _NUMERIC_ missfmt.;
tables _NUMERIC_ / missing missprint nocum nopercent;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-2 10:43:42
jl60156 发表于 2014-12-2 10:10
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value  missfmt  . ='Missing' othe ...
多谢,可是SAS报错 ERROR: 带引号的字符串“ ”对于数值的输出格式和输入格式都是不可接受的。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-2 12:52:26
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-3 11:23:06
In this case you can recode you data, then you use proc means to summarize into the results as needed.

I set up an example below.  

data test;
   array numvar(*) numvar1-numvar50;
   array charvar(*) $1 charvar51-charvar200;
   do i=1 to 50000;
     do j=1 to dim(numvar);
      if ranuni(123)>0.3 then numvar(j)=ceil(1000*ranuni(123));
          else numvar(j)=.;
         end;
     do j=1 to dim(charvar);
      if ranuni(123)>0.3 then charvar(j)=byte(64+ceil(26*ranuni(123)));
          else charvar(j)=' ';
         end;
         output;
        end;
        keep numvar1-numvar50 charvar51-charvar200;
run;


data test2;

  set test;
  array numvar(*) _numeric_;
  array charvar(*) _character_;
  length var_name $16;
     do j=1 to dim(numvar);
      if numvar(j)=. then x=0;
          else x=1;
          var_name=vname(numvar(j));
          output;
         end;
     do j=1 to dim(charvar);
      if  charvar(j)=' ' then x=0;
          else x=1;
          var_name=vname(charvar(j));
          output;
         end;
         keep var_name x;
run;

proc means data=test2 noprint nway;
class var_name;
var x;
output out=result n= Total mean=RatioOFnotmiss sum=Total_not_miss;
run;

proc print data=result;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-3 12:56:56
jl60156 发表于 2014-12-2 10:10
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value  missfmt  . ='Missing' othe ...
感觉format比较好,可以将数值变量用freq计算,就是你的程序的格式显示的很怪
不知道是不是
proc sql;
select count(*) as NN, count(A) as A_nonmiss, calculated NN-calculated A_nonmiss as A_miss, ....
from AAA;
quit;
就行?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群