我想創建一個向數據集中的變量名添加後綴的宏。下面是我的代碼:SAS:創建一個爲數據集中的變量添加後綴的宏
%macro add_suffix(library=,dataset=,suffix=);
proc sql noprint;
select cat(name, ' = ', cats('&suffix.',name)) into :rename_list separated by ' ' from
dictionary.columns where libname = '&library.' and memname= '&dataset.';
quit;
proc datasets library=&library nolist nodetails;
modify &dataset;
rename &rename_list;
run;
quit;
%mend;
%add_suffix(library=OUTPUT,dataset=CA_SPREADS,suffix=CA);
它提供了錯誤信息:
NOTE: No rows were selected.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference RENAME_LIST not resolved.
NOTE: Line generated by the invoked macro "ADD_SUFFIX".
2 rename &rename_list; run;
-
22
76
NOTE: Enter RUN; to continue or QUIT; to end the procedure.
ERROR 22-322: Expecting a name.
ERROR 76-322: Syntax error, statement will be ignored.
如果我把引號庫和數據集的名字,它的工作原理對於第一塊即值添加到字符串rename_list但不對於PROC數據集的步驟
看起來您正在嘗試添加名稱的前綴。 – Tom
這裏沒有考慮到,但你需要確保名稱長度不超過32個字符。對於重命名部分,我更喜歡CATX,閱讀起來更清晰。 https://gist.github.com/statgeek/82d9f2854edc01560e0f – Reeza