Mastering PROC SQL: Essential Statements for Data Management
1.Joining Tables
Example datasets:
INNER JOIN (only matches)
LEFT JOIN (all sales, add customer if match)
FULL JOIN (everything)
Example 1:
proc sql;
create table va4str as
select distinct usubjid, adt, ady, visit, visitnum, avisit, avisitn, aval as va4str label='xxx'
from adam.adeff
where valid='xxx' and paramcd='xxx'
order by usubjid, avisitn, avisit, adt, ady;
run;
Example 2:
proc sql;
create table xxx as
select distinct studyid, usubjid
from eff_v4sc2
where vsn>0;
run;
proc sql;
create table eff_v4sc4 as
select * from eff_v4sc2
where usubjid in (select distinct usubjid from xxx);
run;
Example 3:
proc sql;
create table ec_eff2 as
select a.*, b.dy as indexady, b.visit as b_v, b.visitnum as b_vn, b.visage as agevis
from ec_eff as a right join indexvs2 as b
on a.studyid=b.studyid and a.usubjid=b.usubjid and a.ady>=b.dy
order by studyid, usubjid, ady;
quit;
Comments
Post a Comment