BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9
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 

 

 

3 REPLIES 3
SuryaKiran
Meteorite | Level 14

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;
Thanks,
Suryakiran
Ranjeeta
Pyrite | Level 9
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

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 740 views
  • 0 likes
  • 3 in conversation