SAS - 仅保留所有变量的观察结果 [英] SAS - Keeping only observations with all variables

查看:60
本文介绍了SAS - 仅保留所有变量的观察结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个会员信息数据集,我想只保留全年连续注册的人.每个人有 12 个变量,一个用于一年中的每个月,以及他们在该月注册的天数.有没有办法为每个月变量的值 >1 的数据创建一个子集?

I have a dataset of membership information, and I want to keep only the people who have been continuously enrolled for the entire year. There are 12 variables for each person, one for each month of the year with how many days during that month they were enrolled. Is there a way to make a subset of the data for just those with a value >1 for each of the month variables?

谢谢!

推荐答案

SAS 有各种汇总函数,这些函数很可能正是您所需要的.请参阅 min()(最小值) 尤其如此,因为它可以让您找到几个变量中的最小值.您可能还想考虑 nmiss()(缺失值的数量) 和 n() (非缺失值的数量)如果您必须处理数据中的缺失值.

SAS has various summary functions that might well be what you're looking for. See min() (minimum) in particular, as it will allow you to find the minimum of several variables. You may also want to consider nmiss() (number of missing values) and n() (number of non-missing values) if you have to deal with missing values in your data.

可以向汇总函数传递这样的变量列表(在数据步骤中):

Summary functions can be passed lists of variables like this (in a data step):

minimum = min(var1, var2, var3);

但是,如果您需要使用大量变量,这可能会变得冗长.幸运的是,SAS 提供了几种引用变量列表的方法,使事情更简洁.您可以阅读这些变量列表这里.要在汇总函数中使用它们,请使用 of 限定符:

However, that can become long winded if you need to use a lot of variables. Fortunately, SAS provides several ways to reference lists of variables to make things neater. You can read about these variable lists here. To use them in a summary function use the of qualifier:

minimum = min(of var1-var12);
maximum = max(of var:);
blanks = nmiss(of _NUMERIC_);

最后,您将要使用新发现的数据来决定是否包含哪些数据.要在数据步骤中执行此操作,请查看 output 语句 (用户指南):

Finally you will want to use your new found data to decide whether what data to include. To do this in a data step look at the output statement (user guide):

if min(of var:) > 1 then output;

或者,如果您想更多地了解 SAS 的语法,您可以通过阅读最后一个链接来尝试使用隐式输出.

Or if you feel like learning a bit more about SAS's syntax you could try using an implicit output by reading through the last link.

一般来说,最好提出具体问题并展示您目前在 SO 上的工作,我建议您在学习基础知识时使用谷歌来回答您的基本问题.有很多很棒的文档可以帮助您.

这篇关于SAS - 仅保留所有变量的观察结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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