0
votes

I am trying to use temporary array embedded in SAS Macro, but doesn't recognize when I am trying to get the value from there. Here's a portion of my SAS code:

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;

My main question is how can I make the program recognize this variable monthExpA[i]? I really appreciate your help. Thank you!

1
What SAS code are you trying to get the macro statements to generate? Write out the code you want to create first and make sure it works. Then you could possible use a macro to help generate that code. Note that if you have an array then you probably want normal data step statement and not macro statements. - Tom

1 Answers

0
votes

You cannot get macro code to recognize monthExpA[i] as anything other than a string of 12 characters. You need to use normal SAS code to use the arrays.

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