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
Opal | Level 21

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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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