楼主: fyfzhdsfdx
7515 24

SAS根据多个列筛选有效数据 [推广有奖]

21
boe 发表于 2013-6-10 13:34:38
貌似缺失值应该先处理一下。。。
Gorgeous girl , I love !

22
fyfzhdsfdx 发表于 2013-6-10 16:51:04
boe 发表于 2013-6-10 13:30
前面那个靠谱些,后面那个_col6 还有缺失值,具体原因未知。
还请大牛们给指点一下子。。。。。。
十分感谢您的细心指点。
附件是变量的解释。我想对_col4,_col5,_col25-_col30重新写判断它们有效性的条件。不仅每列的值在选项范围内,并且要符合答题条件。如果看了附件有什么疑惑请及时和我联系。下面是我写的代码,但感觉不对,好像输出的结果有点少,求改进。
%macro valid(r);
%do i=1 %to &r;
data b&i;set a&i;
if not((((_col4=2) and  missing(_col5)) or ((_col4=1) and _col5 in(1,2,3))) and
((_col25=1 and _col26 in(1,2,3,4) and  _col27 in(1,2) and _col28 in(1,2,3,4,5,6)and _col29 in(1,2,3) and _col30 in(1,2,3)) or
(_col25=2 and  missing(_col26) and missing(_col27) and missing(_col28) and missing(_col29) and missing(_col30))) and
((_col27=1 and _col28  in(1,2,3,4,5,6) and _col29  in(1,2,3) and _col30  in(1,2,3))or
(_col27=2 and missing(_col28) and missing(_col29) and missing(_col30)))) then output;
run;
%end;
%mend morevalid;
%morevalid(22);
source.doc (31.5 KB)

23
boe 发表于 2013-6-10 18:00:11
试试
  1. if _col4=1 and not missing(_col5)
  2.            or _col4=2 and not missing(_col6);
  3. else if _col25=1 and _col27=1 and not missing(of _col26 _col28-_col30)
  4.            or _col25=1 and not missing(_col26) and _col27=2 and missing(of _col28-_col30)
  5.            or _col25=2 and missing(of _col26-_col30);
复制代码
Gorgeous girl , I love !

24
fyfzhdsfdx 发表于 2013-6-12 10:58:13
boe 发表于 2013-6-10 18:00
试试
十分感谢您的及时回复。
sas里missing的函数好像没有missing(of _col28-_col30)的用法,因为有ERROR 72-185: MISSING 函数调用参数过多;我试了一下,如果写成missing(_col28-_col30)则相当于只对missing(_col30)进行判断;
您写的if...else if也有error,如下:
160: 无法确定 LINE 和 COLUMN。
NOTE: NOSPOOL 已打开。用 OPTION SPOOL 重新运行可恢复出错的 LINE 和 COLUMN。
ERROR 160-185: 没有匹配的 IF-THEN 子句。
还有我觉得第4题的结果不会影响第6题,只会对第5题产生影响。
我改了一下,并运行,感觉是对的,您看一下,见下。就是不知道还有没有简单的code。
%macro morevalid(r);
%do i=1 %to &r;
data final&i;set school_valid&i;
if ((_col4=1 and not missing(_col5))
           or (_col4=2 and missing(_col5)))
and ((_col25=1 and _col27=1 and not missing(_col26) and not missing(_col28) and not missing(_col29)and not missing(_col30))
           or (_col25=1 and not missing(_col26) and _col27=2 and missing(_col28)and missing(_col29)and missing(_col30))
           or(_col25=2 and missing(_col26)and missing(_col27)and missing(_col28)and missing(_col29)and missing(_col30)));

run;
%end;
%mend morevalid;
%morevalid(22);

25
boe 发表于 2013-6-12 11:39:14
fyfzhdsfdx 发表于 2013-6-12 10:58
十分感谢您的及时回复。
sas里missing的函数好像没有missing(of _col28-_col30)的用法,因为有ERROR 72- ...
嗯,else if换成if就可以了。
Gorgeous girl , I love !

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 06:14