亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

SAS Merge

標簽:
MySQL 大數據

SAS Day 22: Merge

Background:

Sometimes we need to obtain information from different datasets, how do we combine two or more datasets in SAS?

Most cases, we use the “Merge” statements, however,  depends on the data structures, we need to use SQL if it is many to many mapping.
P.S. regardless of Merge or SQL, we need to have at least a specific common variable.

Problem:

We want to combine the information from ADSL(Patients General Infomation) and ADTTE (Time to Event Dataset).

[caption id=“attachment_1476” align=“alignnone” width=“500”]image

ulleo / Pixabay[/caption]

Solution:

First we sort the ADSL and ADTTE dataset by the same common variable “USUBJID”, then we merge these datasets by selecting the records in both of the datasets.

SAS Code:

data pop;
  set adsl ;
  by usubjid; /*Always remember to Sort before Merge;*/
run; 

data adtte;
   set adam.adtte;
   by usubjid adt;
run;

/*Merge the records in both ADTTE and POP*/
data survival;
  merge adtte(in=b) pop(in=a);
  by usubjid;
  if a and b;
  run;

Output:

image

Basic Syntax:

There are 3 steps for Merge Statement to work properly.

  1. Sort the datasets need to be MERGE.
  2. Make sure the common "BY" variable have the same name and length
  3. Merge the datasets with desired selections using the BY variable.

I have summarized the following code for most used Two Data Set Merge Cases:

data survival;
  merge adtte(in=b) pop(in=a);
  by usubjid;
  if a and b;
* if a; /* Select the records in a*/
* if a and not b; /* Select the records in a but not in b*/
  run;

Merge more than two datasets:

data a b c1;
  merge adtte(in=b) pop(in=a) adresp(in=c);
  by subjid;
  if a and b then output a;
  if a and c then output b;
  if a and not c then output c1;
  run;

It is important to know that Merge works for one-to-one or one to many mapping.  Next time we will go over SQL for many to many mapping.

Happy Studying! 😇

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消