在SAS宏中使用临时阵列

时间:2019-04-23 19:55:56

标签: arrays sas sas-macro

我正在尝试使用嵌入在SAS Macro中的临时数组,但是当我试图从那里获取值时无法识别。 这是我的SAS代码的一部分:

array months{13} $ _temporary_ ( 'MAR2019' 'APR2019' 'MAY2019' 'JUN2019' 'JUL2019' 'AUG2019' 'SEP2019' 
                   'OCT2019' 'NOV2019' 'DEC2019' 'JAN2020' 'FEB2020' 'MAR2020');
array monthExpA{13} _temporary_ ('31MAR2019'd '30APR2019'd '31MAY2019'd '30JUN2019'd '31JUL2019'd '31AUG2019'd '30SEP2019'd 
                   '31OCT2019'd '30NOV2019'd '31DEC2019'd '31JAN2020'd '29FEB2020'd 70.6);
array monthExpB{13} _temporary_ (&clockstartdate '01APR2019'd '01MAY2019'd '01JUN2019'd '01JUL2019'd '01AUG2019'd '01SEP2019'd 
                   '01OCT2019'd '01NOV2019'd '01DEC2019'd '01JAN2020'd '01FEB2020'd 70.6);

array totExpectp{13} totExpectp1-totExpectp13;

month1 = 'Feb2019';
monthExpect1 = 0;
totalExpect1 = 0;
flg = 0;
totExpectp[1] = 0;



%do i = 1 %to 13; %put putn(monthExpA[&i],date9.);
    flg = 0;
    month = months[&i];
    %let cutoffd = %totalExpect(monthExpA[i],0); 
    %put &cutoffd;
    %if %sysfunc(month(/*monthExpA[i]*/ cutoffd)) eq %sysfunc(month(&cutoffdate)) 
        and %sysfunc(year(/*monthExpA[i]*/'22Apr2019'd)) eq %sysfunc(year(&cutoffdate)) %then %do;
        %put "Test0;";
        flg = 1;
        %put cutoffd;
    %end;%end;

我的主要问题是如何使程序识别此变量monthExpA [i]?非常感谢您的帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

除12个字符的字符串外,您无法获取宏代码来将monthExpA[i]识别为其他任何内容。您需要使用常规的SAS代码才能使用阵列。

do i=1 to 13;
  flg = 0;
  month = months[i];
  ...