Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created September 25, 2020 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save statgeek/3dd1af207cc55fdc0260d0c7a2457848 to your computer and use it in GitHub Desktop.
Save statgeek/3dd1af207cc55fdc0260d0c7a2457848 to your computer and use it in GitHub Desktop.
SAS - export all files in a library
/*This program exports all files from a library into CSV files.
Author: F. Khurshed
Date: 2020-09-25
*/
options dlcreatedir;
proc options option=dlcreatedir;
run;
%let lib2export = WORK;
%let path2files = /home/demo/;
*list of files;
data _null_;
set sashelp.vtable(where = (libname = "&lib2export") keep = libname memname);
*create folder path for files to be stored;
folder4file = catt("&path2files.", memname);
*use libname to create folders;
rc_open = libname('demo1', folder4file) ;
rc_close = libname('demo1');
file2export = catt(folder4file, "/", memname, ".csv");
length str $300.;
str = catt("proc export data=",
"&lib2export.",
".",
memname,
" outfile=",
trim(quote(file2export)),
" dbms=csv replace;run;");
call execute (str);
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment