Search notes:

SAS: proc export

Export data set to a .txt file

The following example creates a data set and exports it to a .txt file.
data tq84_data;

  infile datalines;

  length col_1 $10
         col_2 $10
         col_3 $10;

  input col_1 col_2 col_3;

datalines;
x y z
one two three
foo bar baz
strawberry blackberry blueberry
;

proc export
     data=tq84_data
     outfile='p:\ath\to\exported.txt';
     putnames=no;
run;
Github repository about-SAS, path: /programming/proc/export/to-txt-file.sas

Using the keep option

In order to restrict the exported variables (attributes), the keep attribute can be used. Apparently, it must immediately follow the data=... statement:
data tq84_data;

  infile datalines;

  length col_1 $10
         col_2 $10
         col_3 $10;

  input col_1 col_2 col_3;

datalines;
x y z
one two three
foo bar baz
strawberry blackberry blueberry
;

proc export
     data=tq84_data(keep=col_1 col_3)
     outfile='p:\ath\to\exported.txt';
     putnames=no;
run;
Github repository about-SAS, path: /programming/proc/export/keep.sas

Using the replace option

By default, proc export cancels the export if the destination file already exists.
However, the export can be forced with the replace option.
data tq84_data;

  infile datalines;

  length num   8
         txt  $20
  ;

  input num txt;

datalines;
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
10 ten
;
run;

proc export

     data=tq84_data (where=(txt gt 'm'))
     outfile='p:\ath\to\exported.txt'
     
     replace;
     putnames=no;
     
run;
Github repository about-SAS, path: /programming/proc/export/replace.sas

Create an Excel file

data tq84_xls;
     do num = 1 to 100;
        txt = put(num, words30.);
        output;
     end;
run;

%let xls_file_name=p:\ath\to\excel\file.xls;

proc export
     data    = tq84_xls
     dbms    = xls
     outfile ="&xls_file_name";

     sheet="all";
run;


proc export
/*   Sine &xls_file_name already exists, a *.bak file
     will additionally be created. */ 

     data    = tq84_xls(where=(num <= 10))
     dbms    = xls
     outfile ="&xls_file_name";

     sheet="first ten";
run;
Github repository about-SAS, path: /programming/proc/export/dbms/xls/create-excel.sas

See also

SAS programming: proc

Index