请选择 进入手机版 | 继续访问电脑版
楼主: yixuehanlin
15682 9

[问答] 请教各位大神,如何统计每个变量的缺失值 [推广有奖]

  • 0关注
  • 0粉丝

本科生

10%

还不是VIP/贵宾

-

威望
0
论坛币
66 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
226 点
帖子
18
精华
0
在线时间
121 小时
注册时间
2012-1-18
最后登录
2024-2-19

yixuehanlin 发表于 2014-12-2 09:49:20 |显示全部楼层 |坛友微信交流群

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
请教各位大神,如何统计每个变量的缺失值,有270多个变量,50000多个观测,现在想要统计每个变量的缺失情况,也就是每一列的缺失情况,缺失值有.和空格两种,大部分都是character变量,少部分数值型,只要统计缺失和不缺失两种情况即可,万分感谢!
二维码

扫码加我 拉你入群

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

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

关键词:缺失值 Character 万分感谢 多个变量 数值型 如何 统计

jl60156 发表于 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;
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Tigflanker + 5 + 3 + 3 + 3 救命了,thx
jingju11 + 5 + 5 + 5 + 5 should be the best one!

总评分: 论坛币 + 10  学术水平 + 8  热心指数 + 8  信用等级 + 8   查看全部评分

使用道具

yixuehanlin 发表于 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: 带引号的字符串“ ”对于数值的输出格式和输入格式都是不可接受的。

使用道具

mingfeng07 学生认证  发表于 2014-12-2 12:52:26 |显示全部楼层 |坛友微信交流群
  1. proc sql;
  2. select count(*) into:n from a;
  3. quit;
  4. proc transpose data=a out=b;
  5. run;
  6. data c(keep=_name_ missing);
  7. set b;
  8. missing=cmiss(of col1-col%left(%trim(&n.)));
  9. run;
复制代码

使用道具

bobguy 发表于 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;

使用道具

teqel 发表于 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;
就行?

使用道具

teqel 发表于 2014-12-3 12:59:39 |显示全部楼层 |坛友微信交流群
bobguy 发表于 2014-12-3 11:23
In this case you can recode you data, then you use proc means to summarize into the results as neede ...
感觉不如format效率高

使用道具

王贴贴123456 在职认证  发表于 2018-10-18 09:37:52 |显示全部楼层 |坛友微信交流群
jl60156 发表于 2014-12-2 10:10
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value  missfmt  . ='Missing' othe ...
赞赞赞

使用道具

伯克西昂 发表于 2021-10-22 01:24:19 |显示全部楼层 |坛友微信交流群
format方法好用,感谢!

使用道具

zzhouar 发表于 2023-11-23 12:48:57 |显示全部楼层 |坛友微信交流群
jl60156 发表于 2014-12-2 10:10
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value  missfmt  . ='Missing' othe ...
赞赞赞

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 03:41