a********a 发帖数: 346 | 1 I am cleaning a data set as following, if all 36 variable are missing, I am
going to delete the observation. The following program works for me, but I
do not think it is a good program. Please help me if you have a better idea
to change the array part of my program.
Thanks
data mis;
set spt_dloc;
array m{36} ALT48SI CLAD48SI COD48SI PEA48SI EGG48SI MILK48SI SOYA48SI
WHEA48SI GRAS48SI
CAT48SI DOG48SI HDM48SI
ALTERNARIAMEANDIAMETER_10 CLADOSPORIUMMEANDIAMETER_10
|
f********t 发帖数: 117 | 2 I have a couple of ideas. they are pretty much same.
create of new column which is the product of all the 36 columns. this asume
they are all numbers.
then you check to see newcolumn is .
same idea in proc sql .
SELECT * from (select S.*, COALESCE (s.ALT48SI, .... 36 columns) AS
newcolumn from spt_dloc) nn where newcolumn = .
or you can do select * from spt_dloc where ALT48SI = . and 36 columns here.
|
s*r 发帖数: 2757 | 3 do these columns stay together? |
g*******y 发帖数: 380 | 4 可以不用array,记得可以用其它方法选择所有变量,所有数字变量或者所有字符变量
,google一下吧。 |
h******e 发帖数: 1791 | 5 是这些吗?_all_, _character_, _numeric_
【在 g*******y 的大作中提到】 : 可以不用array,记得可以用其它方法选择所有变量,所有数字变量或者所有字符变量 : ,google一下吧。
|
c*******o 发帖数: 3829 | 6 Since all the variables are numeric, the following codes should work:
data mis (drop=total);
set spt_dloc;
array m{*} _all_;
total= sum(of m{*});
if total ne . then output;
run; |
p********a 发帖数: 5352 | 7 如果变量都连在一起,可用如下搞定:
data non_mis;
set spt_dloc;
if sum(of ALT48SI--HDMMEANDIAMETER_18) ne .;
run; |
w***y 发帖数: 114 | 8 proc contents data=A(drop=variable list you donot need) out=B(keep=name);
proc sql;
select name into:var separated by ", "
from B
;
quit;
data C;
set A;
d=sum(&var);
if d=. then delete;
run; |
a********a 发帖数: 346 | 9 Thank you all for giving great ideas. If you use sum function, I am afraid
it will give wrong result.
For example,
a b
1 .
1 2
. .
if you let sum=a+b, it will give
a b sum
1 . .
1 2 3
. . .
If fact I only want the observations with both a and b are missing. |
S***e 发帖数: 108 | 10 data mis;
set spt_dloc;
array m{36} ALT48SI CLAD48SI COD48SI PEA48SI EGG48SI MILK48SI SOYA48SI
WHEA48SI GRAS48SI
CAT48SI DOG48SI HDM48SI
ALTERNARIAMEANDIAMETER_10 CLADOSPORIUMMEANDIAMETER_10
CODMEANDIAMETER_10 PEANUTMEANDIAMETER_10 EGGMEANDIAMETER_10
MILKMEANDIAMETER_10 SOYAMEANDIAMETER_10 WHEATMEANDIAMETER_10
GRASSMEANDIAMETER_10 CATMEANDIAMETER_10 DOGMEANDIAMETER_10
HDMMEANDIAMETER_10
ALTERNARIAMEANDIAMETER_18 CLADOSPORIUMMEANDIAMETER_18
CODMEANDIAMETER_18 PEANUTMEANDIAMETER_18 EGGMEANDIAMETER |