Proc sql;
Create table NWHC_DAD as
Select distinct
A.*
From NWHC_service as A
Left join DAD as D
On A.ID=D.ID and A.ID~=’9999999999’
Where D.fyear=2016 and A.days_to_servdate<=D.days_to_servdate+60
;quit;
Proc sql;
Create table NWHC_NRS as
Select distinct
A.*
From NWHC_service as A
Left join NRS as N
On A.ID=N.ID and A.ID~=’9999999999’
Where D.fyear=2016 and A.days_to_servdate<=N.days_to_servdate+60
;quit;
I need to combine the three tables in one step so that I have a final table which has the IDs where the foll condition is satisfied along with the other conditions in the query : days_to_servdate from the A table is <= days_to servdate from table D or days_to servdate From table N
Please advise how would i do that
Joining three tables
Hello,
What join do you need? INNER or LEFT. For me it looks like you need an inner join for your requirement.
Proc sql;
Create table NWHC_DAD as
Select distinct
A.*
From NWHC_service as A
inner join DAD as D On A.ID=D.ID and A.ID<>'9999999999'
inner join NRS as N On A.ID=N.ID and A.ID<>'9999999999'
Where D.fyear=2016 and ( A.days_to_servdate<=N.days_to_servdate or A.days_to_servdate<=D.days_to_servdate)
;quit;
proc sql;
create table NWHC_DAD_NRS as
select distinct
A.*
from NWHC_service as A
left join DAD as D
on A.ID=D.ID and A.ID~='999999999'
where A.days_to_servdate <=D.days_to_admdate+60 and fyear_ddate=2016
left join NRSdisrecs as N
on A.ID=D.ID and N.ID~='999999999'
where A.days_to_servdate <=N.days_to_admdate+60 and fyear_ddate=2016
group by id
order by id
;quit;I wanted to do a left join to keep all records in A
Please advise how would i correc the query above to apply all the conditions
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.