在SAS中的宏内创建数据集

时间:2015-08-14 16:30:17

标签: sas sas-macro

我可以使用以下方式创建多个数据集:

data D3RGDPX  (drop=BasePeriod BaseYear Forecast10Year)
 D3GDPX   (drop=BasePeriod BaseYear Forecast10Year)
 D3BFIX   (drop=BasePeriod BaseYear Forecast10Year)
 D3CPAT   (drop=BasePeriod BaseYear Forecast10Year)
 D3IP     (drop=BasePeriod BaseYear Forecast10Year)
 D3TPHS   (drop=BasePeriod BaseYear Forecast10Year)
 D3PPI    (drop=BasePeriod BaseYear Forecast10Year)
 D3CPI    (drop=BasePeriod BaseYear Forecast10Year)
 D3UNPR   (drop=BasePeriod BaseYear Forecast10Year) 
 D3WMFG   (drop=BasePeriod BaseYear Forecast10Year)
 D3RTTR   (drop=BasePeriod BaseYear Forecast10Year)
 D3AUTODF (drop=BasePeriod BaseYear Forecast10Year)
 D3SPIF   (drop=BasePeriod BaseYear Forecast10Year);
 set my.data;
     if      Type='RGDPX'  then output D3RGDPX;
     else if Type='GDPX'   then output D3GDPX;
     else if Type='BFIX'   then output D3BFIX;
     else if Type='CPAT'   then output D3CPAT;
     else if Type='IP'     then output D3IP;
     else if Type='TPHS'   then output D3TPHS;
     else if Type='PPI'    then output D3PPI;
     else if Type='CPI'    then output D3CPI;
     else if Type='UNPR'   then output D3UNPR;
     else if Type='WMFG'   then output D3WMFG;
     else if Type='RTTR'   then output D3RTTR;
     else if Type='AUTODF' then output D3AUTODF;
     else if Type='SPIF'   then output D3SPIF;
run;

我尝试在宏中执行此操作,但每次宏都会覆盖另一个宏,这样只剩下最后一个数据集,并且它不会创建多个数据集。如何在宏中完成此任务?

从评论中添加:

%macro new (data=, set=, Type=); 
data &data (drop=BasePeriod BaseYear Forecast10Year); 
set my.data; 
if Type = "&Type" then output &data; 
run; 
%mend new;
 %new (data =D3RGDPX, Type = RGDPX); 
%new (data=D3GDPX, Type=GDPX);

等等。

0 个答案:

没有答案