将多个数据集合并在一起

Merging multiple datasets together

您好,我有一个清单让我苦苦挣扎,因为我认为我使用的代码没有正确完成工作。这是规格。

数据集:首先通过USUBJID,IDVARVAL=QSSEQ,合并QS和SUPPQS,只保留QSCAT='SOFA'的记录。然后通过USUBJID和QSSEQ与ADSOFA合并。仅在 MITTFL='Y'

处保留记录

这是我使用的代码

proc sql;

create table qs (where=(qscat="SOFA" )) as

select a.*,b.qnam as SOFASCS,qval as avalc_qs from trans.qs as a

left join

trans.suppqs (where=(qnam='SOFASCS')) as b

on a.usubjid = b.usubjid and a.qsseq = input(b.idvarval,best.);

quit;



proc sort data=qs;

by usubjid qsseq;
run;



data adsofa;

set adb.adsofa;
run;



proc sort data=adsofa;

by usubjid qsseq;
run;



data qs01;

merge qs(in=a drop=studyid)
adsofa(in=b where=(mittfl = "Y"));

by usubjid qsseq;

if a or b;

我不断收到我不想要的行。有更简洁的方法吗?

我试着把你的逻辑转换成经典的SQL。

proc sql;
  create table qs as
    select a.*
        ,b.qnam as SOFASCS
        ,qval as avalc_qs
    from trans.qs as a
    left join trans.suppqs as b
        on a.usubjid = b.usubjid and a.qsseq = input(b.idvarval,best.) and qnam='SOFASCS'
    where qscat="SOFA" ;
quit;

proc sql;
  create table qs01 as
    select qs.*, a.*
    from qs 
    full /* left? */ join adb.adsofa as a
        on a.usubjid = qs.usubjid and a.qsseq = qs.qsseq and mittfl = "Y"
  ;
quit;

我假设你真的不想有一个完整的连接,而是最后一个简单的左腰。