SAS - 表达式中%内的宏错误

时间:2014-01-14 12:31:15

标签: sas-macro

我写了这段代码:

%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 ;,它就完美了!。

1 个答案:

答案 0 :(得分:2)

您必须通过%sysfunc()包含每个尝试过的函数调用。

%让我的工作方式像复制粘贴一样,所以它不够“聪明”,不能自动识别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.