SAS中文论坛

标题: 【求助】如何自动读入变量名? [打印本页]

作者: shiyiming    时间: 2009-3-30 15:07
标题: 【求助】如何自动读入变量名?
我有一个数据库,有几十个变量。
这些变量中有些数据缺失被设成不同的缺失值(比如-99, -977)。
我想全部查找替换成“.”
我不知道怎样才能实现。

请问高手怎样一次性把所有变量名都读入一个宏变量中,然后循环一下把每个变量里面的缺失值替换掉。(或者有没有其他更好的办法)

谢谢!

数据库:
var1 var2 var3 var4 var5....
1      -99    2      3     4
-977    2    3     1       5
.....

怎样把这些缺失值都变成点?
作者: shiyiming    时间: 2009-4-6 07:21
标题: Re: 【求助】如何自动读入变量名?
First I think you have to make sure that there are no value for a certain variable that equals to the possible missing values, either -977 or -99 or whatever..

If not, you may try following code.

data test1(drop=i);
  set test;
  array var_array {5} var1-var5;
  do i=1 to 5;
      if var_array{i} in (-99,-977) then var_array{i}=.;
         end;
         run;

Also, if your variables were not set as var1 , var2 or whatever, you can use the following more universe code

data test1(drop=i);
  set test;
  array nvar(*) _numeric_;
     do i=1 to dim(nvar);  
          if nvar(i)in (-977,-99) then nvar(i)=.;
     end;
         run;




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2