3
votes

I'm trying to get started using SAS. I create a dataset in which the number of variables is dependent on the period chosen by a user. What I want to do is loop trough these variables. The macro I'm trying to use for this is (I justed fixed date for the example):

%MACRO DO_PERIOD;
    %DO I = 1 %TO %SYSFUNC(intck('month', "01JUL2008"d, "31JUL2009"d));
        %PUT %I
    %END;
%MEND DO_PERIOD;

Unfortunately running this macro yields the following error:

ERROR: A character operand was found in the %EVAL function or %IF 
condition where a numeric operand is required. 
The condition was: %sysfunc(intck('month', "01JUL2008"d, "31JUL2009"d)) 
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro DO_PERIOD will stop executing.

I tried numerous ways of evaluating the intck function (e.g. %eval(%sysfunc(....)), using input(...)), but without any results. I hope someone of you knows the answer to evaluating a function in a %do statement.

1

1 Answers

4
votes

A few issues:

  1. In macro, there is no need to quote literals (eg 'month') - everything is treated as text.
  2. You missed a semicolon in the %put statement
  3. You need an AMPERSAND to denote the macro variable (not a % sign, which invokes a macro)

See:

%MACRO DO_PERIOD;
  %DO I = 1 %TO %SYSFUNC(intck(MONTH, "01JUL2008"d,"31JUL2009"d)); 
    %PUT &I; 
  %END; 
%MEND; 
%DO_PERIOD;