BookmarkSubscribeRSS Feed
PharmlyDoc
Quartz | Level 8

 

This question is similar to mine:

https://communities.sas.com/t5/SAS-Procedures/Using-bind-variables-in-PROC-SQL-query-to-Oracle-datab...

 

I am querying an Oracle database from SAS, and I am unable to create temporary tables within the Oracle database. 

I find proc sql explicit pass-through to be the fastest method for querying the database. 

 

What I want to do is define a macro variable within SAS called PatID, and then passthrough the value for PatID to a bind variable called pat_id_var within Oracle. The following code returns "ERROR: ORACLE execute error: ORA-01008: not all variables bound." 

 

%LET PatID='123456789';
proc sql;
CONNECT TO ORACLE(AuthDomain='OracleAuth' PATH= );
execute (DECLARE pat_id_var varchar2(18);
begin :pat_id_var := &PatID. ;
end;
) by ORACLE;
create table work.WANT as
select * 
from connection to oracle (
select PatientID
from oradb.PATIENTS 
where PatientID = :pat_id_var
);
disconnect from ORACLE;
quit;

My goal is to hide the true value of PatID in both SAS log and Oracle. 

The following code does not hide the PatID value when I view the sql statement in Oracle:

%LET PatID='123456789';
proc sql;
CONNECT TO ORACLE(AuthDomain='OracleAuth' PATH= );

create table work.WANT as
select * 
from connection to oracle (
select PatientID
from oradb.PATIENTS 
where PatientID = &PatID.
);
disconnect from ORACLE;
quit;

Thanks for any insight! 

 

 

3 REPLIES 3
Tom
Super User Tom
Super User

You probably cannot do what you are trying. You have to either run a command (EXECUTE) or run a query (FROM CONNECTION TO) in PROC SQL.

 

And even if you it did work it would probably still show the patid in the SQL logs.

PharmlyDoc
Quartz | Level 8

So, when querying Oracle from SAS using proc sql, it's not possible to hide values that are part of the SQL statement? 

SASKiwi
PROC Star

What is the business need to hide PATID, given it is in the SAS table you are creating and the Oracle table you are querying. If this column is that sensitive it should be encrypted in Oracle and then you would query on the encrypted value.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 2315 views
  • 0 likes
  • 3 in conversation