Hello,
Like many organizations, we have many databases which contains many tables and for which we have little documentation. So, in some case, it is difficult to find the good table to carry out some tasks.
So I wonder it there is a way to find a specific value into a table.
For example, imagine that we have the oracle data base named dbase1 which contains many tables and I would like to look into each table and retains only the table name containing a specific value, let's say the value test.
Is there an efficient way to do that in sas.
Regards,
Hello,
I have try many things. The first table is populated but the table test1 and test2 are empty. Of course due to that factor,
I can't use the table cols for the last script. Moreover, for the last script, I am getting this error:
ERROR: ORACLE execute error: ORA-01008: not all variables bound.
Heres my codes. Please note that some letter are replace by ??? for safety purpose.
Also, I was note able to declare a val variable and to set it at predefined value such as KING, CFNAUL, in my case
**********************
SQL> variable val varchar2(10) SQL> exec :val := 'KING' PL/SQL procedure successfully completed. SQL> SELECT DISTINCT SUBSTR (:val, 1, 11) "Searchword", 2 SUBSTR (table_name, 1, 14) "Table", 3 SUBSTR (column_name, 1, 14) "Column" 4 FROM cols, 5 TABLE (xmlsequence (dbms_xmlgen.getxmltype ('select ' 6 || column_name 7 || ' from ' 8 || table_name 9 || ' where upper(' 10 || column_name 11 || ') like upper(''%' 12 || :val 13 || '%'')' ).extract ('ROWSET/ROW/*') ) ) t 14 ORDER BY "Table" 15 /
************************
***********************
%let TblName=list_of_tables;
%let WantedValue='CFNAUL';
%let authdomain=ORACLE_SAS_???_HUBPROD;
%let path=%sysfunc(scan("&authdomain.",-1,"_"));
working .....
proc sql;
connect to oracle(authdomain="&authdomain" path="&path");
create table &TblName. as
select * from connection to oracle
( select (&WantedValue.) as val,
owner,
Table_Name,
Column_Name as Field_Name
from all_tab_columns
)
order by owner, table_name, Field_Name;
quit;
Not working. The cols table as variables but no values.
proc sql;
connect to oracle(authdomain="&authdomain" path="&path");
create table test as
select * from connection to oracle
( select (&WantedValue.) as val,
/* owner,*/
Table_Name,
Column_Name as Field_Name
from cols
)
order by /*owner,*/ table_name, Field_Name;
quit;
Not working. The table cols has variables but no values.
proc sql;
connect to oracle(authdomain="&authdomain" path="&path");
create table test2 as
select * from connection to oracle
( select *
from cols
)
;
quit;
This one , I can't use the table cols and I am getting a bounding error.
proc sql;
connect to oracle(authdomain="&authdomain" path="&path");
create table &TblName. as
select * from connection to oracle
( select (&WantedValue.) as val,
Table_Name,
Column_Name as Field_Name
from all_tab_columns,
TABLE (xmlsequence (dbms_xmlgen.getxmltype ('select '
|| column_name
|| ' from '
|| table_name
|| ' where upper('
|| column_name
|| ') like upper(''%'
|| :val
|| '%'')' ).extract ('ROWSET/ROW/*') ) ) t
);
quit;
Does someone could help me with those issue such as how to declare variable and assign value to it , while using
the SQL pass through facility.
Also, could I use another table then all_tab_columns because the cols does not have value in it.
Regards,
Surely you have staff in your organisation that are responsible for creating and maintaining the tables in these databases. Why not ask them to help find the best source of the data you are looking for? A data dictionary wont tell you what is the best or most appropriate source for the data you want.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.