BookmarkSubscribeRSS Feed
JB1974
Calcite | Level 5

Hoping someone can help.

I am using SAS Enterprise Guide 4.3 - connecting into Oracle to pull back data.  The information I am returning is personid Status, Start Time, End Time and Last Date Timestamp.

Here is the problem - for the Last Date Timestamp, I am trying to determine a way to only return the records for the most recent timestamp.  Below is the code that is running, but it has been running for over 3 hours.

select * from connection to oracle

( select

  abc.person_id

  ,abc.status

  ,abc.start_time

  ,abc.end_time

  ,tmp.last_ld_ts

  From

  [my table name] abc

  ,(select max(to_number(to_char(last_ld_ts, 'YYYYMMDD'))) as max_last_ld_ts from [my table name]) tmp

  where

    abc.person_id = 5897 and

    to_number(to_char(abc.last_ld_ts, 'YYYYMMDD')) = tmp.max_last_ld_ts

);

disconnect from oracle;

1 REPLY 1
TomKari
Onyx | Level 15

Should your sub-query have a WHERE clause for person_id? Otherwise, how do you know you're getting the latest date for that person, as opposed to just the general latest date?

However, that shouldn't make it run slow, it should just return no data. I don't see anything offhand that should cause long delays. Two general suggestions for troubleshooting:

1. Try running this query under your SQL client directly (is it still SQL*PLUS?), and see how long it takes. If it returns what you're expecting very quickly, then the problem is probably on the SAS side. Otherwise, it's probably on the Oracle side, and has nothing to do with SAS.

2. SAS has a SASTRACE option that can be used to display the actual code that SAS sends to Oracle. Although in this case I believe it will be exactly the code you've written, it could be worth a try.

Keep us posted!

  Tom

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1055 views
  • 0 likes
  • 2 in conversation