--- %%NOBANNER%% -->
/*-------------------<-- Start of Description-->---------------------\
| Export a sas data to an external file; |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|------------<-- Start of Files or Arguments Needed-->---------------|
| Argument: |
| indata: input data set you want to export; |
| outfile: the file your want to dump your sas data set to; |
| dbms: |
| ACCESS Microsoft Access database .MDB |
| DBF dBASE file .DBF |
| WK1 Lotus 1 spreadsheet .WK1 |
| WK3 Lotus 3 spreadsheet .WK3 |
| WK4 Lotus 4 spreadsheet .WK4 |
| EXCEL Excel Version 5 spreadsheet .XLS |
| EXCEL4 Excel Version 4 spreadsheet .XLS |
| EXCEL5 Excel Version 5 spreadsheet .XLS |
| EXCEL97 Excel 97 spreadsheet .XLS |
| DLM delimited file (default delimiter is a blank) .* |
| CSV delimited file (comma-separated values) .CSV |
| TAB delimited file (tab-delimited values) .TXT |
| replace: if a file with the same name exists, |
| T - overwrite it, |
| F - append to it; |
|-------------<-- End of Files or Arguments Needed-->----------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %export(indata=attest.covar, outfile=c:\temp.xls); |
| Usage: %export(indata=, outfile=, dbms=tab, replace=t); |
\-------------------<-- End of Files Created-->---------------------*/
%macro export(indata=, /* Input data set */
outfile=, /* Output excel spread sheet */
dbms=tab, /* DBMS can be CSV, tab, ... */
replace=t); /* Replace the existing file? */
/*--------------------------------------------\
| Author: Duo Zhou; |
| Created: 7-20-2001 9:17pm; |
| Purpose: Export a sas data to an external |
| file, such as excel spread sheet; |
\--------------------------------------------*/
%let data=%qscan(&indata,1,%str((),));
%local fileref;
%let fileref=%qscan(&outfile,1,%str((),""''));
%if &dbms ne %then %do;
%let dbms=%upcase(&dbms);
%end;
%else %do;
%let dbms=TAB;
%end;
%if &replace ne %then %do;
%let replace=%upcase(&replace);
%end;
%else %do;
%let replace=T;
%end;
%put --> Note: Wait! The system is writing "&data" to the file;
%put --> "&fileref". ;
%if (&fileref ne) %then %do;
%let dsid=%sysfunc(fileexist(&fileref));
%if (%quote(%upcase(&replace))=T) and (&dsid) %then %do;
%put ==> Alert! File "&fileref";
%put ==> is being overwritten. ;
%end;
proc export data=&data
outfile="&fileref" DBMS=&dbms %if (%quote(%upcase(&replace))=T) %then %do;
REPLACE
%end;;
run;
%end;
%else %do;
%put ==> Alert! You forgot to give me an output file.;
%end;
%mend export;