如果我寫有內容的test.sas:如何我使用%包括調用SAS宏
%macro test;
%put test macro;
%mend;
%test;
然後就是在SAS會話中執行此:
%include test.sas
威爾它只是調用宏'測試'?或者它是否只包含宏定義,但跳過執行?
如果我寫有內容的test.sas:如何我使用%包括調用SAS宏
%macro test;
%put test macro;
%mend;
%test;
然後就是在SAS會話中執行此:
%include test.sas
威爾它只是調用宏'測試'?或者它是否只包含宏定義,但跳過執行?
%include
就像在外部文件上打F3一樣。它會嘗試編譯和執行文本文件中的所有內容。所以,如果你打開mcompilenote=all
和你的程序是:
%macro test;
%put test macro;
%mend;
%test;
日誌將讀取:
8 %macro test;
9 %put test macro;
10
11 %mend;
NOTE: The macro TEST completed compilation without errors.
6 instructions 80 bytes.
12 %test;
test macro
但是,如果你的程序是:
%macro test;
%put test macro;
%mend;
日誌將改爲:
8 %macro test;
9 %put test macro;
10
11 %mend;
NOTE: The macro TEST completed compilation without errors.
6 instructions 80 bytes.
它將執行文件中的語句,就像它們被包含在原始程序中的行一樣。所以它將首先定義宏,然後當最後一行運行時它將執行宏。
是的,它會工作正如你最初所建議的那樣 - 它會編譯並運行宏。
我會注意到,良好的編程風格將是在您的實際程序中有宏調用(如果這就是你所做的)。這就像一個C++頭文件:宏包含'要做什麼',然後你實際調用它在你的實時代碼中 - 不僅是爲了好的樣式,而且是爲了能夠重新運行它,而無需重新編譯它,如果你需要(修復某事,說)。