07-15-2015 11:49 AM
My OS is Linux and I made this to obtain the table with paths:
rc2=system("du -k > /data/projects/smartdata/librerie/listfolders.txt");
PROC IMPORT OUT= WORK.listfolders
And I have also this macro:
libname lib_tmp "&folder_path.";
*list library detailed contents;
create table List_lib_contents as
where libname="LIB_TMP" and memtype in ('DATA','CATALOG');
*count the number of rows;
if 0 then set work.List_lib_contents nobs=n;
*verify for files;
%if &nrows > 0 %then %do;
libname oldlib "&folder_path.";
filename tranfile "&file_path.";
proc cport lib=oldlib file=tranfile;
Can I call this macro using perhaps like parameter the paths which are in the sas table obtained?
07-15-2015 12:22 PM
Sure, see my working example on GitHub, and specific to your situation below. I don't see (or missed) how filepath is specified in your macro or data so you'll need to work that out as well. The actual macro execution is commented out, I like to verify my macro call first and then run it.
string = catt('%list_folder_contents(age=' folder_path, ',', filepath, ');');
07-15-2015 04:52 PM
to make a list of SAS data sets, use proc contents, which requires a libname statement for the listing.
since you want to search a folder and sub-folders
check this page on making lists.
you need to figure out which way you are going to do these tasks.
in order to use cport you need a libref.data_set_name.
your Q implicitly stated that you wanted to search for files named data_set_name.sas7bdat
and then automagically cport them.
doing a recursive call to a make-list-folders is non-trivial.
I would use a DOS directory command to find all the folders containing *.sas7bdat
then parse that to a set of folders that are arguments to the libname::libref statements for use by contents
Here is a tool to call a macro using a data set as list of parameter values.
1. make list of folders
dir *.sas7bdat /S >list-of-folder-with-data-sets.txt
2. edit that file and get one row per folder, save as list-folders.csv
3. import list-folder.csv to data-set list_folders
4. write and test macro cport with parameters data and transport-file-name
5. write and test macro make_list_folders_data with parameters folder
libname temp "&folder";
proc contents data = temp._all_
out = out_contents;
attrib folder length = $256;
retain folder "&folder";
proc append data = &syslast
base = list_folders_data_sets;
libname temp clear;*important! libref TEMP is reused;
this macro is called for each row of list_folders
6. use data set list_folders_data_sets to call macro cport
ah, yes, there is a slight problem with naming collisions in the cport transport filenames.
every data set ought to be written to a same-name-as-data-set transport file
that is easy to guarantee when reading from one folder
but not, in your case, multiple folders which may contain same names in different folders.
one solution to consider: sequentially number the transport files with either a prefix or suffix
your cport macro can increment a global macro variable
%let cport_N = 1;
%let cport_N = %eval(&cport_N+1);