SAS:如果观察与另一个数据集中的观察匹配,则从数据集中删除观察 [英] SAS: Remove observations from data set if they match an observation in another data set

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

问题描述

我正在学习 SAS.这是一个非常简单的问题——我可能想多了.

I'm just learning SAS. This is a pretty simple question -- I'm probably overthinking it.

我有一个名为 people_info 的数据集,其中一个变量是 SocialSecurityNum.我有另一个名为 invalid_ssn 的表,其中包含一个变量:唯一和无效的 SocialSecurityNum 观察.

I have a data set called people_info and one of the variables is SocialSecurityNum. I have another table called invalid_ssn with a single variable: unique and invalid SocialSecurityNum observations.

如果人员(观察)的 SocialSecurityNum 与以下值之一匹配,我想要一个 DATA 步骤(或 PROC SQL 步骤)输出到 invalid_people_infoinvalid_ssn 表.否则,它将输出回people_info.

I would like to have a DATA step (or PROC SQL step) that outputs to invalid_people_info if the SocialSecurityNum of the person (observation) matches one of the values in the invalid_ssn table. Otherwise, it will output back to people_info.

这样做的最佳方法是什么?

What's the best way to do this?

更多信息,澄清...

people_info 看起来像这样:

name     SocialSecurityNum
joe      123
john     456
mary     876
bob      657

invalid_ssn 看起来像这样:

SocialSecurityNum
456
876

我想要的是 people_info 改变(就地)并看起来像这样:

What I want is for people_info to change (in place) and look like this:

name     SocialSecurityNum
joe      123
bob      657

和一个名为 invalid_people_info 的新表,如下所示:

and a new table, called invalid_people_info to look like this:

name     SocialSecurityNum
john     456
mary     876

推荐答案

您的需求不明确.您想从 people_info 中删除所有无效的 SSN 并将它们放入一个新的数据集中吗?如果是这样,这应该有效.您必须先按 SocialSecurityNum 对数据集进行排序.

Your requirement isn't clear. Do you want to remove all the invalid SSNs from people_info and put them into a new dataset? If so, this should work. You'll have to sort your datasets by SocialSecurityNum first.

data people_info invalid_people_info;
    merge people_info (in=a) invalid_ssn (in=b);
    by SocialSecurityNum;
    if b then output invalid_people_info;
    else output people_info;
run;

这篇关于SAS:如果观察与另一个数据集中的观察匹配,则从数据集中删除观察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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