我在宏中解析宏變量時遇到問題。我認爲問題在於語言,以及SAS如何將語句發送到宏處理器與編譯器。SAS宏函數與數據階躍函數
這裏是我的代碼JIST:
....some import statements...
%MACRO FCERR(date=);
%LET REMHOST=MainFrame PORT;
SIGNON REMHOST USER=&SYSUSERID. PASSWORD= _PROMPT_;
%SYSLPUT date=&yymm. ;
RSUBMIT;
FILENAME FIN "MY.FILE.QUALIFIERS" DISP = shr;
......some datasteps......
LIBNAME METRO "My.File.Qualifiers" DISP=shr;
/********************************************************************
******* *********
** ** **
******* ** * **
** ** * **
******* *********
*
/*******************************************************************/
%IF %SYSFUNC(EXIST(work.EQ_&date._FIN)) %THEN %DO;
PROC UPLOAD Data = work.EQ_&date._FIN
OUT = work.EQ_&date._FIN;
..........a bunch of data steps..................
PROC SQL NOPRINT ;
select count(*) as EQB format=10.0 INTO :EQBEF from EQ_1701_FIN ;
select count(*) as EQA format=10.0 INTO :EQAFTER from trunc_fin_eq ;
QUIT ;
%PUT &EQBEF;
%PUT &EQAFTER;
%IF %SYSFUNC(STRIP(&EQBEF.)) ~= %SYSFUNC(STRIP(&EQAFTER.)) %THEN %DO;
options emailhost= MYEMAILHOST.ORG ;
filename mail email ' '
to= (&recip.)
subject = "EQ Error QA/QC";
DATA _NULL_;
file mail ;
put "There were potential errors processing the Equifax Error file.";
put "The input dataset contains %SYSFUNC(STRIP(&EQBEF.)) observations.";
put "The output dataset contains %SYSFUNC(STRIP(&EQAFTER.)) observations.";
put "Please check the SAS log for additional details.";
RUN;
%END;
%END;
%ENDRSUBMIT;
%SIGNOFF;
%MEND;
%FCERR(date=&yymm.);
我不斷收到正在從處理停止我的宏出現錯誤。這是它:
> SYMBOLGEN: Macro variable EQBEF resolves to 24707
> 24707
> MLOGIC(FCERR): %PUT &EQAFTER
> WARNING: Apparent symbolic reference EQAFTER not resolved.
> &EQAFTER
> SYMBOLGEN: Macro variable EQBEF resolves to 24707
> WARNING: Apparent symbolic reference EQAFTER not resolved.
> WARNING: Apparent symbolic reference EQAFTER not resolved.
> ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
> operand is required. The condition was: %SYSFUNC(STRIP(&EQBEF.)) ~=
> %SYSFUNC(STRIP(&EQAFTER.))
> ERROR: The macro FCERR will stop executing.
問題:是SAS試圖處理我的第二個(即內部)%IF%,那麼聲明它編譯和執行上述%IF %SYSFUNC(STRIP(&EQBEF.)) ~= %SYSFUNC(STRIP(&EQAFTER.)) %THEN %DO;
數據步驟,我可以從日誌SAS是抽看之前出它正在創建從我datasteps數據集之前,我相信&EQBEF
被解決的原因是因爲它使用PROC UPLOAD;
如果是這樣產生的錯誤,我怎樣才能防止SAS從IF%,那麼直到執行第二%數據處理將被處理,因爲proc sql;
中的第二條select
聲明依賴於數據安全執行。
此外,我無法讓我的日期變量在proc sql中解析;
E.G.
PROC SQL NOPRINT ;
select count(*) as EQB format=10.0 INTO :EQBEF from EQ_1701_FIN ;
select count(*) as EQA format=10.0 INTO :EQAFTER from trunc_fin_eq ;
QUIT ;
理想的是:
PROC SQL NOPRINT ;
select count(*) as EQB format=10.0 INTO :EQBEF from EQ_&DATE._FIN ;
select count(*) as EQA format=10.0 INTO :EQAFTER from trunc_fin_eq ;
QUIT ;
但&日期。不會在那個proc sql語句中解析,但是在我所有的libname語句中都可以很好地解決,等等。爲什麼&日期有一些意外情況。在PROC SQL中不能解析?.....我需要在參數列表中引用的宏中使用每個變量嗎?
閱讀這幾次之後,我明白了這個問題,以及如何解決它。我所做的是在Rsubmit中使用'PROC SQL SELECT COUNT(*)'語句,使用'%SYSRPUT'將遠程服務器上的值賦給本地服務器上的值,然後處理我的'%IF%THEN'語句本地。我確實有一個問題,'%let mvar = Local'的目的是什麼,然後像'%put LOCAL &=mvar;'那樣引用它?我很困惑'LOCAL &=mvar;'一塊。 '&=';是什麼意思?我從未見過以這種方式構建的東西...... – DukeLuke
'%put&= mvar'是'%put MVAR =&mvar'的新縮寫。我添加了額外的文本LOCAL和REMOTE到%put,這樣你就可以知道哪條語句在日誌中生成了該行。 – Tom