sas 通过整个数据降低价值 [英] sas drop value through the whole data

查看:33
本文介绍了sas 通过整个数据降低价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将无效值转换为单个值,并且它们仅打印具有这些值的 obs 的 ID=> 我有多个错误是第二部分(循环),是否可以以某种方式修复此代码,或者根本不可能这样做?

I want to turn invalid values to a single value and them print only the ID's of the obs that has these values=> I have multiple error is the second part (the loop), is it possible to fix somehow this code, or is it simply impossible to do that this way?

data comb8;set comb;
if q2 not in (1,2,3,4,5)then q2=666;
if q3 not in (1,2,3,4,5)then q3=666;
if q10 not in (1,2,3,4,5)then q10=666;
if gender not in(0,1)then gender=666;
if married not in(0,1)then married=666;
run;

data comb10; set comb8;
do i=1 to n;
if i NE 666 then drop(?????????);
end;
keep id;
run;

推荐答案

希望我理解正确 - 您所追求的最终结果是保留包含无效值的任何观察的观察编号 任何您要检查的标准?如果是这样,试试这个:

Hoping I've understood this right - the end result you're after is to just keep the obervation number of any observation that contains an invalid value for any of the criteria you're checking for? If so, try this:

data comb8(keep=id where=(not missing(obid)));
  set comb;
  if q2  not in (1,2,3,4,5) then obid=_n_;
  if q3  not in (1,2,3,4,5) then obid=_n_;
  if q10 not in (1,2,3,4,5) then obid=_n_;
  if gender not in(0,1) then obid=_n_;
  if married not in(0,1) then obid=_n_;
run;

_n_ 是一个自动变量,用于标识已从 set 语句加载的观察编号.您可以在发现问题时将 obid 设置为此值,然后使用 (where=(not missing(obid))) 仅保留具有无效值的观察

_n_ is an automatic variable that identifies the observation number that has been loaded in from the set statement. You can set obid to this value when an issue is found and then use (where=(not missing(obid))) to only keep the observations that had invalid values

以防万一以后对其他人有帮助...

Just in case it's of help to anyone else later on...

data comb8;set comb;
if q2 not in (1,2,3,4,5)then q2=666;
if q3 not in (1,2,3,4,5)then q3=666;
if q10 not in (1,2,3,4,5)then q10=666;
if gender not in(0,1)then gender=666;
if married not in(0,1)then married=666;
run;

data comb10(keep=obid where=(not missing(obid)));
  set comb8;
  Array Q q1-q10 gender married . ;
  do i=1 to dim(Q) ;
    if Q[i] EQ 666 then obid=_n_;
  end;
run;

这篇关于sas 通过整个数据降低价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆