我想写一个运行追加10个查询结果的宏,我用SAS宏代码生成。
%MACRO APPENDTEST;
PROC SQL;
%DO I = 1 %TO 12
CREATE TABLE WORK.APPENDTEST AS
SELECT t1.OrderID, t2.Name, t3.Product, t1.Date, t1.Units
FROM DVJAYESH.CANDY_SALES_HISTORY t1,
DVJAYESH.CANDY_PRODUCTS t3,
DVJAYESH.CANDY_CUSTOMERS t2
WHERE (t1.ProdID = t3.ProdID AND t1.Customer = t2.CustID)
AND t1.Date BETWEEN CATS('01', %PUT(CATS(&I), $MTH_NAME.), '2003')D AND
CATS('31', %PUT(CATS(&I), $MTH_NAME.), '2003')D
ORDER BY t1.Date, t2.Name, t3.Product;
%END;
QUIT;
%MEND APPENDTEST;
%APPENDTEST;
我收到多个错误。第一个是 - A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.
请解释并纠正。
仅供参考:我是SAS编程的新手。我使用SAS ENTERPRISE GUIDE
答案 0 :(得分:0)
你的宏将创建work.appendtest 12次。每次都写过以前的副本。您可以尝试在do循环之前放置create语句。 我更喜欢略有不同的方法。
%Macro apendtest;
delete data = appendtest; /* you will get a warning if it doesn't exist;*/
%do i = 1 %to 12;
proc sql;
create table temp as
select ......
from...........
where ..........
quit;
proc append base = appendtest data = temp; run;
%end;
%Mend appendtest;
如果你想看每个临时表使用temp& i