2014-01-14 44 views
0

我寫了這個代碼:SAS - %以內宏錯誤,如果表達

%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

但如果我把%讓hoy = 14,它的作品完美!

+0

所以...你有什麼問題嗎? –

+0

嗨。我的問題是我必須編寫代碼才能通過表達式「&hoy = 14」獲取錯誤。 – user3129222

回答

2

您必須用%sysfunc()括起您嘗試的每個函數調用。

%讓作品像複製粘貼一樣,所以它不足以「自動」識別當天()和今天()是功能。試試這個:

/* 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. 
+0

tx man!宏是簡單的,但你需要看到它在成爲專家之前工作! – user3129222

+0

不客氣。如果你不介意,請標記爲最佳答案:) – realtemper