BookmarkSubscribeRSS Feed
saikiran_nemani
Obsidian | Level 7
How should we Modify the Code ?

Proc sql;
create table SROin_2 as
		select
			/* Before = Faults */
			before.urn,
			before.Close_Date,
			before.Close_Date			as	dayt,
			before.dayt 				as fault_checked_date, /** 07/12/2010 - JW - Added this date in to statement **/
			before.TECH_no1,
			before.WORKORDER,
			before.finding_desc,
			before.solution_desc,
			before.source_system_code,
			before.franchise_Code,
			before.account_no,
			before.trucked_fault,
			/* After = SROs */
			/* PR-added COMPLETIONDATE (P0002373164)*/
			after.ENTRYDATE,
			after.ENTRYDATE				as	dayt,
			after.COMPLETIONDATE,
			after.workorder				as SRO_WO,
			after.SERVICE_CODE,
			after.TECH_NO1				as A_Tech_No1
		from Closed_Faults as before left join
			 SROs as after
		on  before.urn = after.urn
			and before.dayt le after.dayt
			and after.dayt lt (before.dayt + 1 + 1)
			and after.urn ne ""
		order by before.dayt, urn;
quit;

Modified Code

Proc SQL;
Create table SROin_2 as
Select
        /* Before = Faults */
Coalesce(before.closeddate,open.schedule_date) as faultdate,
                  before.urn,
                  before.Close_Date,
                  before.Close_Date as    dayt,
                  before.dayt             as fault_checked_date, /** 07/12/2010 - JW - Added this date in to statement **/
                  before.TECH_no1,
                  before.WORKORDER,
                  before.finding_desc,
                  before.solution_desc,
                  before.source_system_code,
                  before.franchise_Code,
                  before.account_no,
                  before.trucked_fault,
                  /* After = SROs */
                  /* PR-added COMPLETIONDATE (P0002373164)*/
                  after.ENTRYDATE,
                  after.ENTRYDATE                     as    dayt,
                  after.COMPLETIONDATE,
                  after.workorder                     as SRO_WO,
                  after.SERVICE_CODE,
                  after.TECH_NO1                      as A_Tech_No1
from SROs as SRO 
left join 
Closed_Faults as before on sro.urn=before.urn 
and SRO.Opendate lt (before.dayt+1)
left join
Open as Open ON SRO.URN = OPEN.URN
and SRO.Opendate lt (OPEN.SCHEDULE_DATE+1)
where Before.URN IS NOT NULL OR OPEN.URN IS NOT NULL
order by before.dayt,urn;
QUIT;
2 REPLIES 2
andreas_lds
Jade | Level 19
What's the question/problem?
smijoss1
Quartz | Level 8

pick one unique identifier and put that into where clause 

and then compare the output to your desired output. 

 

community is to give ideas or direct in a path that leads to solution. not write the code for you

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 544 views
  • 0 likes
  • 3 in conversation