为了账号安全,请及时绑定邮箱和手机立即绑定

SAS Proc SQL Join

标签:
MySQL 大数据

SAS day 24: Proc SQL Join

Review:

Last time we went to over SAS Merge, it is a SAS Merge statement used for 1 - 1 mapping or One - Many mapping,

What should we do for many to many mapping?

Problem:

Suppose we want to generate a dataset which has the combined info from both dataset A and B.
*Note: Data A and B both have more than 1 record for each patient. *

Sample Dummy Dataset:
Dataset A
Dataset A

Dataset BDataset B

Solutions:

  1. One-sided Join( Left join or Right join) Suppose we want to join dataset A to all the records in dataset B
    Keywords: right join / Left join

image

SAS Code:

proc sql noprint nowarn;
create table example as 
select distinct b.*,  a.pt, a.transyn
from a right join  b 
on a.pt=b.pt
;
quit;

2. Intersection (Inner Join)
Suppose we want to produce all the records that contained in both Dataset A and Dataset B
Keywords: inner join

image

SAS Code

proc sql noprint nowarn;
create table example as 
select distinct b.*,  a.pt, a.transyn
from a inner join  b 
on a.pt=b.pt;
quit;
3. Union (full Join)

Suppose we want to generate a dataset that contains either dataset A or dataset B
Keywords: full join

image

proc sql noprint nowarn;
create table example as 
select distinct b.*,  a.pt, a.transyn
from a full join  b 
on a.pt=b.pt
;
quit;

4. Join with conditionsSuppose we want to select all the records with Transyn="Yes"
Keywords: where

image

SAS Code:

proc sql noprint nowarn;
create table exam_inner as 
select distinct b.*,  a.pt, a.transyn
from a inner join  b 
on a.pt=b.pt
where transyn="Yes"
;
quit;

Summary:
A lot of times we need to combine the info from two datasets or more, in order to amalgamate the info efficiently,
we use SAS Merge for 1 - 1 or 1- many mapping with at least one common key variables,
and use Proc SQL to generate the datasets with many to many mappings.

Happy studying!!! 🤨

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消