I have several files created with SAS in the WORK directory. They are grouped as follows:
ABAR_blabla_14
ABAR_blabla_15
ABAR_blabla_16
BLOP_blabla_14
BLOP_blabla_15
BLOP_blabla_16
CLUF_blabla_14
CLUF_blabla_15
CLUF_blabla_16
There are also other files whose names do not begin with "ABAR," "BLOP," or "CLUF."
I want to save only the files that begin with "ABAR," "BLOP," or "CLUF."
The destination folder path is: '/export/home/name-2356/Folder'
I want to create a macro for this, but I have no idea how to do it. The macro should automatically save each dataset as a .txt file with the same name as the dataset in the WORK folder: like CLUF_blabla_16.txt and so on
2
If the datasets all have the same structure (same variables in the same order) then you could do it all with one data step, so no code generation is needed at all.
data _null_;
length dsname filename $255 ;
set ABAR: BLOP: CLUF: indsname=dsname ;
filename = cats('/export/home/name-2356/Folder/',lowcase(scan(dsname,-1,'.')),'.txt');
file txt filevar=filename dsd ;
put (_all_) (+0);
run;
Otherwise get the list of datasets and generate a separate step to export each one.
proc contents data=work._all_ noprint out=contents; run;
data _null_;
set contents;
by memname;
where memname in: ('ABAR' 'BLOP' 'CLUF');
if first.memname;
call execute(catx(' ','proc export'
,'data=',catx('.',libname,nliteral(memname))
,'dbms=csv','outfile='
,quote(cats('/export/home/name-2356/Folder/',lowcase(memname),'.txt'))
,'replace;','run;'
));
run;
1