BookmarkSubscribeRSS Feed
lerdem
Quartz | Level 8

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

3 REPLIES 3
overmar
Obsidian | Level 7

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.

ChrisNZ
Tourmaline | Level 20

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

 

 

 

wolowicz
Fluorite | Level 6

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3707 views
  • 0 likes
  • 4 in conversation