r/SQL • • 18d ago

Oracle SQL with SAS

Is it the norm to have a program that is coded in SAS and then need SQL to store the the data? The need SQL tools to pull information about out the tables then swap back to SAS to pull lots of data out quickly? New analyst at a new job and it is exhausting

4 Upvotes

20 comments sorted by

View all comments

0

u/[deleted] 18d ago

[deleted] — view deleted comment

2

u/octocoral 18d ago

This is exactly what I use.

This is my pass-through template for accessing our Oracle database:

proc sql;

connect to oracle

(user=yourloginid password=yourpassword path='servername');

execute (alter session set current_schema=yourschema) by oracle;

create table test_data as

select * from connection to oracle

(your SQL code goes here);

disconnect from oracle;

quit;

This code sends the Oracle-specific SQL code to the server and returns the results into a SAS dataset named test_data. Then, it is within SAS and you can process the data as you wish.

1

u/Agreeable_Ad4156 17d ago

Even with pass thru SQL, SAS won’t let you write — comments, which I use a lot of.

1

u/octocoral 17d ago

Odd, it does for me.

Also, it will pass SAS macro variables to the server. I will set a macro variable as a date, then Oracle can read it as a date, e.g.

TRUNC( completion_dttm ) BETWEEN TO_DATE( &start_date, 'DDMonYY' ) AND TO_DATE( &end_date, 'DDMonYY' )