这篇文章为代码备份,代码参考SAS编程:如何将数据集批量输出到Excel?。
Review数据集时,将数据集批量输出到EXCEL中进行简单的筛选查询,是一个比较实用的方法。为了程序稳定、快速运行,输出采用proc export
的方法。
以下为代码备份,方便引用。
***1. Set library and Excel file;
libname adam "/xxx/adam" access = readonly;
%global libname excel;
%let libname = ADaM;
%let excel = /xx/xxx/20210144_adam_&sysdate..xlsx;
***2. Create the macro;
%macro exp_dt(lib=, res=);
**2.1 Get datasets name and number in the library;
data memname;
set sashelp.vtable end = eof;
where libname = %upcase("&lib.") ;
call symputx("name"||strip(put(_n_, best.)), strip(memname));
if eof then call symputx("nobs", strip(put(_n_, best.)));
run;
%put name1 = &name1;
%put nobs = &nobs;
**2.2 Export all the datasets;
%macro loop;
%do i = 1 %to &nobs;
proc export data=&lib..&&name&i.
outfile="&res."
dbms=xlsx replace;
sheet = "&&name&i.";
run;
%end;
%mend loop;
%loop;
%mend exp_dt;
***3. Invoke the macro ;
%exp_dt(
lib = %str(&libname.)
,res = %str(&excel.)
);
感谢阅读,欢迎关注:SAS茶谈!
若有疑问,欢迎评论交流!