Proc SQL

作者: 不连续小姐 | 来源:发表于2018-11-08 08:27 被阅读0次

SAS Day 16: Proc SQL 1

Case When

Problem:

Suppose we need to merge the SDTM.VS (Vital Sign) dataset with SDTM.SE (Subject Element) for Epoch Infomation. We will assign the EPOCH to VS if the VSDY is between SESTDY and SEENDY.

Example: Usubjid=TF-001-001-001, VISIT=SCREENING, VSDY=-6, EPOCH=SCREENING

image image

Background:

SAS Merge is perfect for 1 to 1 merge or many to 1 merge.
Such as, 1 record in dataset A merges with 1 record in dataset B.
1 record in dataset A merges with many records to dataset B, or vice versa.

Proc SQL is used/ Must be used for Many to Many merges.

[caption id="attachment_941" align="alignnone" width="750"] image

kaboompics / Pixabay[/caption]

Solution:

  create table dummy as
  select a.*, b.epoch
  from dummy_vs as a left join dummy_se as b
  on case  when a.usubjid = b.usubjid
  and epoch="SCREENING"
and  b.sestdy <= a.vsdy < b.seendy then "screening"
when a.usubjid = b.usubjid
  and epoch="TREATMENT"
and  b.sestdy <= a.vsdy < b.seendy then "treat"
when a.usubjid = b.usubjid
  and epoch="FOLLOW-UP"
and  b.sestdy <= a.vsdy <= b.seendy then "follow"
end ;
quit;

Output:

image

Note: We need to use Proc Sort Nodupkey to after Proc SQL to get the unique records.

Thanks very much to Cindy to remind me SE means Subject Elements!

Happy SAS Coding! 😇

相关文章

  • Proc SQL

    SAS Day 16: Proc SQL 1 Case When Problem: Suppose we need...

  • SAS 高级 习题 SQL

    1. Which of the clauses in the PROC SQL program below is ...

  • SAS Proc SQL Join

    SAS day 24: Proc SQL Join Review: Last time we went to o...

  • sas语句

    /修改结果变量长度/proc sql;alter table amodifyx char(3),y num(5);...

  • sql左匹选择条件

    proc sql; create table base_20_1 as select a.*,b.WEEK,b.n...

  • flink sql 时区不对

    proc.proctime的模式格式是 java.sql.Timestamp 发现时间不对,现在时间18:44:0...

  • ROC曲线

    install.packages('pROC') #下载pROC包 library(pROC) #调用pROC包 ...

  • shell记录

    查看基本信息 都在 /proc 下cat /proc/cpuinfocat /proc/mtd 免breed更新路...

  • Linux下的proc目录详解

    文章结构: 1.什么是proc目录 2. 初识proc目录 3. 从proc窥看系统详情 1.什么是proc目录 ...

  • 性能问题定位

    系统信息 /proc虚拟目录,是内存的映射 cat /proc/version cat /proc/cpuinfo...

网友评论

    本文标题:Proc SQL

    本文链接:https://www.haomeiwen.com/subject/usjixqtx.html