本文介绍了SAS 数据合并存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 sas 新手,我有两个数据集如下,
I am new to sas, i have two datasets as following,
data datasetA;
input a $1;
datalines;
1
2
3
4
5
6
7
;
run;
data datasetB;
input a $1;
datalines;
1
3
5
7
;
run;
如果a出现B,那么我想要的输出应该是
If a appears B, then my desired output should be
1 Y
2 N
3 Y
4 N
5 Y
6 N
7 Y
推荐答案
这至少可以通过两种方式实现:
This can be achived by in at least two ways:
merge
通过data step
或left join
与proc sql
.
merge
via thedata step
orleft join
with theproc sql
.
此 pdf 比较了 sas 中合并与 sql 的优缺点.
This pdf compares pros and cons of merge versus sql in sas.
既然 rbet 向您展示了如何使用合并步骤执行此操作,我将向您展示如何使用 proc sql
执行此操作.
Since rbet showed you how to do this with the merge step, I'll show you how to do it with the proc sql
.
proc sql;
create table work.result as
select t1.a, case when t2.a is not missing then 'Y' else 'N' end as exists
from work.datasetA t1
left join work.datasetB t2 on t1.a = t2.a order by t1.a;
这篇关于SAS 数据合并存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!