我想根據字段值(parent_account)將一個SAS表導出到多個Excel工作表中。我希望每個工作表的名稱與parent_account相同。我使用的代碼是http://www.tek-tips.com/viewthread.cfm?qid=1335588,但我收到以下錯誤消息:基於字段值將一個SAS表導出到多個Excel工作表中
在需要數字操作數的%EVAL或%IF條件中找到字符操作數。 宏函數%SCAN的參數2不是數字。
%macro export_to_excel();
%local varlist idx var;
proc sql noprint;
select distinct parent_account into: varlist separated by '||'
from todays_activity;
quit;
%let idx = 1;
%do %while (%scan(&varlist, &idx, %str(||)) ne %str());
%let var=%scan(&varlist, &idx, %str(||));
proc export data=sashelp.class (where=(parent_account="&var"))
outfile='My file location\Report.xls'
dbms=excel;
sheet="&var";
quit;
%let idx = %eval(&idx + 1);
%end;
%mend export_to_excel;
%export_to_excel;
您正在使用什麼版本的SAS。如果您使用的是當前版本,則可以嘗試使用ODS EXCEL並調整何時爲每個BY組創建新工作表。然後用BY語句使用PROC PRINT。 – Tom
對不起,我應該提到這一點。我正在使用SAS Enterprise Guide 7.11。 –
EG會話連接到哪個版本的SAS對於EG版本更重要。 – Tom