BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
phoenix31
Fluorite | Level 6

Hello All,

 

I have an Oracle query which pulls in data from the previous Business day however I am trying to convert this to a SAS query (Proc SQL Statement) and need help converting previous day Business day (M-F) in SAS.

 

Oracle code:

select * from tablename where columnname  BETWEEN  decode(to_char(sysdate,'D'),2,trunc(sysdate-3),trunc(sysdate-1)) AND  trunc(sysdate)

 

Can anyone help me with this?

Please let me know if more information is needed.

1 ACCEPTED SOLUTION

Accepted Solutions
phoenix31
Fluorite | Level 6

Thank you so much!

I used your query and updated month to weekday to get business days only.

 

Code:

between intnx('WEEKDAY',today(),0,"b") and intnx('WEEKDAY',today(),-1,"b")

View solution in original post

6 REPLIES 6
phoenix31
Fluorite | Level 6

Thank you.
I used the below to get the desired result:

 

intnx('WEEKDAY',today(),0,"b") and intnx('WEEKDAY',today(),-1,"b")

 

To get only the prior business day data.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use intnx function and today():

decode(to_char(sysdate,'D'),2,trunc(sysdate-3),trunc(sysdate-1)) AND  trunc(sysdate)

Something like:

between intnx('month',today(),0,"b") and intnx('month',today(),1,"b")
phoenix31
Fluorite | Level 6

Thank you so much!

I used your query and updated month to weekday to get business days only.

 

Code:

between intnx('WEEKDAY',today(),0,"b") and intnx('WEEKDAY',today(),-1,"b")

r_behata
Barite | Level 11

You may also consider using SQL Pass-thru for Oracle. That way you can leverage your existing SQL query to get the same result from within sas.

 

Assuming that the SAS/Access to Oracle is licensed :

PROC SQL;    
  CONNECT TO ORACLE (user=user password="password" path=schema);
  CREATE TABLE LIBRARY.tab_nm AS
   SELECT *       
      FROM CONNECTION TO ORACLE          
       (
           <Your query here>
     	);
  DISCONNECT
  FROM ORACLE; 
 QUIT;

 

SuryaKiran
Meteorite | Level 14

You may need to consider running an explicit pass-through instead, if your table is very large. When you change it to SAS Query and use some SAS function then those functions may not be converted to Oracle specific by SAS.

 

In your case your trying to use equivalent SAS functions in where clause, if SAS cannot convert them all of the data without the where clause will be brought to SAS Server and where clause will be applied on SAS side instead of Oracle side.

 

proc sql;
connect to Oracle (user= password= server=);
create table SAS_Table as 
select * 
from connection to Oracle 
(
select * from tablename where columnname  BETWEEN  decode(to_char(sysdate,'D'),2,trunc(sysdate-3),trunc(sysdate-1)) AND  trunc(sysdate)

);
quit;

 

Check this document to see what formats will be applied by default for the data types in Oracle.

 

Thanks,
Suryakiran

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 2863 views
  • 1 like
  • 5 in conversation