我正在尝试运行一个包含多个串联在一起的条件的 proc sql 宏。有没有办法纠正第二个宏(rn_cnt)下面的代码或者有更好的方法?背景:此处的目标是通过执行以下操作来生成丢失数据文件对的计数: 1.) 导入数据 2.) 运行宏来计算丢失记录 3.) 当宏引用报价文件时排除一些客户 ID (由于过去该文件中这些 ID 的数据被错误删除)。 [注意:由于名称过长,文件名和 ID 号已被简化。] 谢谢。
%macro importdt (dataname, source);
proc sql;
create table &dataname as select *
from &source;
quit;
%mend importdt;
%importdt(quotes, sales.quotesall);
%importdt(orders, ordersall);
%importdt(invoices, invoicesall);
%importdt(contracts, contractsall);
%macro rn_cnt (misscust, data1, data2, &dataname);
proc sql;
create table &misscust as select count(distinct cust_id) as Misscnt from &data1
where cust_id not in (select distinct cust_id from &data2) and cust_id not in (('101' '102' 103' '104' '105') when &dataname = quotes);
quit;
%mend rn_cnt;
%rn_cnt(quotes_orders, quotes, orders);
%rn_cnt(quotes_invoices, quotes, invoices);
%rn_cnt(quotes_contracts, quotes, contracts);
%rn_cnt(orders_invoices, orders, invoices);
%rn_cnt(orders_contracts, orders, contracts);
%rn_cnt(invoices_contracts, invoices, contracts);
为什么不直接创建一个数据集,然后使用 SQL 代码插入新的观察结果,以便在调用结束时您可以在一个数据集中获得所有计数。
我无法弄清楚 DATANAME 参数的用途,因为引用的 SQL 代码毫无意义。但如果你修复它们,他们也会创建一个变量来保存它的值。
data misscount;
length ds1 ds2 $32 misscnt 8;
stop;
run;
%macro rn_cnt (data1, data2, &dataname);
proc sql;
insert into misscount
select "&data1","&data2",count(distinct cust_id) as Misscnt
from &data1
where cust_id not in (select distinct cust_id from &data2)
and cust_id not in (('101' '102' '103' '104' '105')
/* What the heck is this?? when &dataname = quotes */
)
;
quit;
%mend rn_cnt;