BookmarkSubscribeRSS Feed
ballardw
Super User

I would be strongly tempted to replace code like

       left join  hmaodm.actv_fact af

       on cdf.case_id = af.case_id

       and  af.cse_src_sys_cd in ('CPM')

with something like

       left join  (select * from hmaodm.actv_fact
                     where cse_src_sys_cd in ('CPM'))  af

       on cdf.case_id = af.case_id

to reduce the number of records brought into the join. You have opportunities for this at many of your joins

ChrisNZ
Tourmaline | Level 20

@ballardw 

Doesn't the SQL parser subset the right table when it sees

and  af.cse_src_sys_cd in ('CPM')

?

ChrisNZ
Tourmaline | Level 20

@ballardw 

Both SQL steps take 4.8s on my machine.

data A(sortedby=I) B(sortedby=I);
  do I=1 to 1e7;
    output;
  end;
run;   
proc sql _method;
  create table T as
  select A.I, b.I as J
  from A left join B on a.I=b.I and b.I=1e7;
quit;
proc sql _method;
  create table T as
  select A.I, b.I as J
  from A left join B(where=(I=1e7)) on a.I=b.I ;
quit;
ballardw
Super User

@ChrisNZ wrote:

@ballardw 

Both SQL steps take 4.8s on my machine.

data A(sortedby=I) B(sortedby=I);
  do I=1 to 1e7;
    output;
  end;
run;   
proc sql _method;
  create table T as
  select A.I, b.I as J
  from A left join B on a.I=b.I and b.I=1e7;
quit;
proc sql _method;
  create table T as
  select A.I, b.I as J
  from A left join B(where=(I=1e7)) on a.I=b.I ;
quit;

Cached data sets?

I haven't tested the suggestion in a while but when I had some data across network drives sub-setting the data had some positive impact in my environment.

ChrisNZ
Tourmaline | Level 20

Interesting. Something to keep one's eyes on then. 

It'd be disappointing if the SQL optimiser did not subset the table. That's such an obvious step.

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
  • 19 replies
  • 1985 views
  • 1 like
  • 4 in conversation