這篇文章為代碼備份勒叠,代碼參考SAS編程:如何將數(shù)據(jù)集批量輸出到Excel欧漱?职抡。
Review數(shù)據(jù)集時(shí),將數(shù)據(jù)集批量輸出到EXCEL中進(jìn)行簡單的篩選查詢误甚,是一個(gè)比較實(shí)用的方法缚甩。為了程序穩(wěn)定谱净、快速運(yùn)行,輸出采用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.)
);
感謝閱讀郊丛,歡迎關(guān)注:SAS茶談李请!
若有疑問,歡迎評(píng)論交流宾袜!