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.

 

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
  • 3 replies
  • 940 views
  • 0 likes
  • 3 in conversation