I have a code as below, i need to take the select max(date) in seperate code. it takes so much time. How can i seperate them
This is the code
proc sql;
create table aa as
select a.vid,
a.activity_date,
a.hour,
a.from_date,
b.req,
b.perehis_act_date
from stg.coa a,
stg.wte b
where a.EMPLOYEE_PIDM = b.perehis_pidm
and b.perehis_act_date = (select max(x.perehis_act_date)
from stg.wte x
where x.perehis_pidm=b.perehis_pidm
and x.perehis_Act_date <= a.from_date )
and datepart(a.from_date) <= (select max(datepart(e.end_date))
from stg.comp e
where today()GE datepart(e.end_date)+14);
quit;
I need this query to simple couple query. Thank you
I think...
proc sql;
create table second as
select max(x.perehis_act_date) as max_prehis
from stg.wte x inner join stg.wte b on (x.perehis_pidm=b.perehis_pidm)
inner join stg.coa a on (perehis_Act_date <= a.from_date);
create second2 as
select distinct b.*
from stg.wte b inner join second m on (b.perehis_act_date=m.max_prehis);
create table third as
select max(datepart(e.end_date)) as e_end_date
from stg.comp e
where today()GE datepart(e.end_date)+14);
create table aa as
select a.vid, a.activity_date, a.hour, a.from_date, b.req, b.perehis_act_date
from stg.coa a inner join second2 b on (a.EMPLOYEE_PIDM = b.perehis_pidm)
inner join third n on (datepart(a.from_date)<= n.e_end_date);
However some of those queries get rather convulted. The essential goal is to create three tables for the final join which have already executed the subqueries. So hopefully I figured out where each of them correctly line up to. Also some of the inner joins may not really need to be inner joins, they may need to be left joins, but the way it was written it looked like they should be inners. Hope this helps.
To speed up your query withuot chaging it, you can:
- Make the second subquery a permanent temporary table since it does not depend on other parameters. Even better, store the result in a macro variable.
- Index table STG.WTE on PEREHIS_PIDM (and possibly PEREHIS_ACT_DATE) to speed up the first subquery's join
Hey there lerdem,
I see you building some Banner Payroll queries in here. shoot me an email at wolowicz@uvic.ca. We are doing some Banner Payroll things in SAS too.
Cheers
Dave
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.