0

我写了这段代码:

%macro puntos_evol;

%let hoy = day(today());

%if &hoy = 14 %then %do;

data prueba;

mes_1 = intnx("month",today(),-1, 'E');
format mes_1 date9.;

run;
%end;
%else %do;
data salida;
dato='no valido';
run;
%end;

%mend puntos_evol;

%puntos_evol;

错误是:

错误:在表达式中找不到必需的运算符:&hoy = 14

但如果我输入 %let hoy = 14;,它就完美了!

4

1 回答 1

3

您必须用 %sysfunc() 封装您尝试的每个函数调用。

%let 的工作方式有点像复制粘贴,因此它不够“聪明”,无法自动识别 day() 和 today() 是函数。尝试这个:

/* just some useful debug options */
options SymbolGen MPrint MLogic MExecNote MCompileNote=all;
dm output 'clear';
dm log 'clear';

/* the code */
%macro puntos_evol;
%let hoy = %sysfunc(day(%sysfunc(today())));
%PUT hoy=&hoy; /* put the date */
%if &hoy = 14 %then %do;
    data prueba;
        mes_1 = intnx("month",today(),-1, 'E');
        format mes_1 date9.;
    run;
%end;
%else %do;
    data salida;
        dato='no valido';
    run;
%end;
%mend puntos_evol;

%puntos_evol;

和日志:

5299  %macro puntos_evol;
5300      %let hoy = %sysfunc(day(%sysfunc(today())));
5301      %PUT hoy=&hoy;
5302      %if &hoy = 14 %then %do;
5303          data prueba;
5304              mes_1 = intnx("month",today(),-1, 'E');
5305              format mes_1 date9.;
5306          run;
5307      %end;
5308      %else %do;
5309          data salida;
5310              dato='no valido';
5311          run;
5312      %end;
5313  %mend puntos_evol;
NOTE: The macro PUNTOS_EVOL completed compilation without errors.
      22 instructions 560 bytes.
5314
5315  %puntos_evol;
MLOGIC(PUNTOS_EVOL):  Beginning execution.
NOTE: The macro PUNTOS_EVOL is executing from memory.
      22 instructions 560 bytes.
MLOGIC(PUNTOS_EVOL):  %LET (variable name is HOY)
MLOGIC(PUNTOS_EVOL):  %PUT hoy=&hoy
SYMBOLGEN:  Macro variable HOY resolves to 23
hoy=23
SYMBOLGEN:  Macro variable HOY resolves to 23
MLOGIC(PUNTOS_EVOL):  %IF condition &hoy = 14 is FALSE
MPRINT(PUNTOS_EVOL):   data salida;
MPRINT(PUNTOS_EVOL):   dato='no valido';
MPRINT(PUNTOS_EVOL):   run;

NOTE: The data set WORK.SALIDA has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

MLOGIC(PUNTOS_EVOL):  Ending execution.
于 2014-01-23T10:36:06.043 回答