I have a table containing a list of libnames and their tables. I'd like to create a subquery to return the minimum createdon date for each listed table, passing the libname and table as the libname.table used in the subquery.
I've created the following:
proc sql;
create table createdon_min as
select *,
cats("(select min(createdon) from "||strip(libname)||"."||strip(table_name)||")") as CREATEDON_FRM
from all_tables1
where freq="DAILY" AND part_date="CREATEDON";
quit;
No error is generated, but the createdon_frm value doesn't execute, it merely creates a string value like "(select min(createdon) from pvaprov.institutional)".
The libname and table resolved correctly, but how do I get the statement to execute as a subquery?
proc sql
support dynamic SQL/prepared statements. – Gordon LinoffSELECT INTO
construct and pass your dynamic statement(s) into macro variables. Then use a macro loop to build a new PROC SQL to execute each statement. – Chris J