您可以使用調用symputX和Global選項來確保宏變量在宏外可用。我想知道你爲什麼需要一個宏,但是:)。 您可能還想了解SAS存儲日期的方式,因爲它們是應用格式的數字。
%MACRO Getdate;
DATA _null_;
infile 'h:\dates.txt';
input @1 date date9.;
call symputx('date_stored', put(date, date9.), G);
run;
%MEND Getdate;
%getdate;
%put &date_stored.;
編輯:根據你的答案/下面的評論:
%MACRO Getdate;
%let date_stored=0;
DATA _null_;
infile 'h:\dates.txt';
input @1 date date9.;
call symputx('date_stored', put(date, date9.), G);
call symputx('start_date', put(date-45, date9.), G);
call symputx('end_date', put(date-14, date9.), G);
run;
%MEND Getdate;
*CHECK if they exist after macro is run;
%put &date_stored;
%put &start_date;
%put &end_date;
有幾個方法可以做到這一點。檢查doco中數據步驟中的'symput'函數。你可能不需要一個已命名的數據集,你可以使用'data _null_'。 – sasfrog 2014-10-02 02:54:47
謝謝sasfrog,我確實看過這些,Reese的邏輯幫助我解決了這個問題。絕對感謝您的意見:)) – vbala2014 2014-10-03 15:15:06