I am currently checking a large number of tables for linking keys(all with different names) between datasets. My current code checks for how many records exist and for how many records have a 0 key value. My code looks like this:
%let table = table1;
proc sql;
create table linking_keys as
select *
from work.my_datasets
where Table_Name = "&table"
and linking_key NE 'N';
quit;
proc sql;
select Column_Name
into :lnkkeycol separated by ','
from linking_keys;
quit;
%put &lnkkeycol;
proc sql;
create table lnk_key_only as
select count(*)
from library1.&table;
quit;
proc sql;
create table lnk_key_only_2 as
select count(&lnkkeycol)
from library1.&table
where &lnkkeycol = 0;
quit;
This works fine when there is only 1 linking key in the table, but when there is multiple, it falls over. I have tried grouping by macro variables but not had much success with the below:
proc sql;
create table lnk_key_only_2 as
select count(&lnkkeycol)
from library1.&table
where &lnkkeycol = 0
group by &lnkkeycol;
quit;
I am not entirely sure where I am going wrong.