This question is similar to mine:
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!
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.
So, when querying Oracle from SAS using proc sql, it's not possible to hide values that are part of the SQL statement?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.