如何删除SAS数据集中的空白观察 [英] How to delete blank observations in a data set in SAS

查看:93
本文介绍了如何删除SAS数据集中的空白观察的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据集中删除所有空白观察.我只知道如何从一个变量中去除空白:

I want to delete ALL blank observations from a data set. I only know how to get rid of blanks from one variable:

data a;
set data(where=(var1 ne .)) ;
run;

这里我设置了一个没有 var1 空白的新数据集.但是,当我想摆脱整个数据集中的所有空白时,该怎么做?

Here I set a new data set without the blanks from var1. But how to do it, when I want to get rid of ALL the blanks in the whole data set?

预先感谢您的回答.

推荐答案

如果您正在尝试删除缺少所有变量的行,这很容易:

If you are attempting to get rid of rows where ALL variables are missing, it's quite easy:

/* Create an example with some or all columns missing */
data have;
set sashelp.class;
if _N_ in (2,5,8,13) then do;
  call missing(of _numeric_);
end;
if _N_ in (5,6,8,12) then do;
  call missing(of _character_);
end;
run;

/* This is the answer */
data want;
set have;
if compress(cats(of _all_),'.')=' ' then delete;
run;

您也可以预先使用 OPTIONS MISSING=' '; 代替压缩.

Instead of the compress you could also use OPTIONS MISSING=' '; beforehand.

如果你想删除所有缺失值的行,那么你可以使用 NMISS/CMISS 函数.

If you want to remove ALL Rows with ANY missing values, then you can use NMISS/CMISS functions.

data want;
set have;
if nmiss(of _numeric_) > 0 then delete;
run;

data want;
set have;
if nmiss(of _numeric_) + cmiss(of _character_) > 0 then delete;
run;

对于所有字符+数字变量.

for all char+numeric variables.

这篇关于如何删除SAS数据集中的空白观察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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