Hi all,
I thought of writing a macro code which can export all the datasets from a library into an excel file.
Here is the code that does the task well.
/* Define macro for export */
%macro autoexp(File, libnm);
%let libval=%upcase(&libnm);
proc sql;
create table tables as
select
libname, memname from
dictionary.tables
where libname="&libval" & memtype="DATA"; * Use double quote only in macros ;
Quit;
data tab;
set tables;
dnm=trim(libname)|| '.' || trim(memname);
run;
proc sql noprint;
select dnm into :dnams separated by '*' from tab;
quit;
/* Export from datasets one by one into the excel file */
%let i=1;
%let dns= %scan(&dnams, &i, %str(*) );
%do %while (&dns ne );
%let sh=%scan(&dns,2);
proc export data=&dns outfile="&file" dbms=excel replace;
sheet="&sh";
run;
%let i=%eval(&i+1);
%let dns= %scan(&dnams, &i, %str(*) );
%end;
%mend autoexp;
/* Calling */
%autoexp(d:\sas output\mass export.xls , syst);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.