Advertisements

2 Quick Ways to Export SAS Data as CSV Files (Example Codes!)

SAS users need to know these 2 quick ways to export SAS data as CSV Files because CSV files can be easily opened in Excel and working in Excel is easier than in SAS. We can use PROC EXPORT to export SAS data to a CSV File. Advanced users can also find the SAS Help Center useful.

2 quick ways to Export SAS Data as CSV Files, SAS Export to CSV, Proc Export SAS CSV, SAS Proc Exprot CSV

Find with Keyword:

Advertisements

How to Export SAS Data as CSV File, SAS Export to CSV, Proc Export SAS CSV, SAS Proc Exprot CSV


1. Generic PROC EXPORT Procedure

The generic PROC EXPORT Statement is as follows:

/* To Export SAS Data as CSV File */

PROC EXPORT data=Dataset_Name
    outfile="Where to Save\FileName.csv"
    DBMS=csv
    REPLACE;
    DELIMITER=" "
run;

The arguments:

2. Create SAS dataset to be exported as CSV File

To create SAS dataset, the DATA STEP is as follows:

* To Create SAS Data set */

data amazon2;
input year company$ ticker$ sales assets ni;
datalines;
2013 AMAZON.COM AMZN 74452 40159 274
2014 AMAZON.COM AMZN 88988 54505 -241
2015 AMAZON.COM AMZN 107006 65444 596
2016 AMAZON.COM AMZN 135987 83402 2371
2017 AMAZON.COM AMZN 177866 131310 3033
2018 AMAZON.COM AMZN 232887 162648 10073
2019 AMAZON.COM AMZN 280522 225248 11588
2020 AMAZON.COM AMZN 386064 321195 21331
2021 AMAZON.COM AMZN 469822 420549 33364
;
run;

/* To Print the dataset created in SAS */

proc print data=amazon2;
run;

The SAS Dataset is as follows:

Export SAS Dataset as CSV FIle

3. Export SAS Dataset as CSV File

To Export the SAS Dataset as CSV File, the example code is as follows:

/*To Export SAS data to CSV File*/

PROC EXPORT data=amazon2
    outfile="C:\wikitekkee\Learning SAS\amazon2.csv"
    DBMS=csv
    REPLACE;
run;

This is the quick way to export SAS dataset as CSV file.

The CSV File is as follows:

Export SAS Dataset as CSV File

4. Generic PROC EXPORT Procedure

To export SAS dataset as Comma Delimited TXT File, the PROC EXPORT Statement is as follows:

Advertisements
/* To Export SAS Dataset as Comma Delimited TXT */

PROC EXPORT data=amazon2
    outfile="C:\wikitekkee\Learning SAS\amazon2.txt"
    DBMS=TAB
    REPLACE;
    DELIMITER=",";
run;

The Comma Delimited TEXT File is as follows:

Export SAS Dataset as Comma Delimited Text File. Export SAS Dataset as TXT File

5. Export SAS Dataset as Pipe Delimited Text File

To export SAS dataset as Pipe Delimited Text File, the PROC EXPORT Statement is as follows:

/* To Create SAS Data set */

data amazon4;
input year company$ ticker$ sales assets ni;
datalines;
2013 AMAZON.COM AMZN 74452 40159 274
2014 AMAZON.COM AMZN 88988 54505 -241
2015 AMAZON.COM AMZN 107006 65444 596
2016 AMAZON.COM AMZN 135987 83402 2371
2017 AMAZON.COM AMZN 177866 131310 3033
2018 AMAZON.COM AMZN 232887 162648 10073
2019 AMAZON.COM AMZN 280522 225248 11588
2020 AMAZON.COM AMZN 386064 321195 21331
2021 AMAZON.COM AMZN 469822 420549 33364
;
run;

/* To Print the dataset created in SAS */

proc print data=amazon4;
run;

/*TO EXPORT SAD Dataset as Pipe Delimited Text File */ 

PROC EXPORT data=amazon4
    outfile="C:\wikitekkee\Learning SAS\amazon4.txt"
    DBMS=TAB
    REPLACE;
    DELIMITER="|";
run;

The Pipe Delimited Text File:

Export SAS Dataset as Pipe Delimited Text file

6. How to Export SAS Dataset as Semicolon Delimited Text File

To export SAS dataset as semicolon delimited Text File, the PROC EXPORT Statement is as follows:

/* To Export SAS Dataset as Semicolon Delimited Text File */

PROC EXPORT 
    data=amazon4
    outfile="C:\wikitekkee\Learning SAS\amazon4.txt"
    DBMS=TAB
    REPLACE;
    DELIMITER=";";
run;

The semicolon delimited file from SAS:

Note:

To Export SAS dataset as semicolon delimited TXT file, the PROC EXPORT statement has the following arguements:

For a video lesson on the how to Export SAS dataset to Excel and Text File, you can watch a video here.

7. How to export and convers SAS dataset into .txt files with UTF8 encoding

Since the PROC EXPORT does not have the encoding option, users can utilize the following codes to export SAS dataset into .txt files with UTF8 encoding.

/* To export SAS dataset into .txt files with UTF8 encoding */

data _null_;
set sashelp.class;
file "C:\wikitekkee\Learning SAS\class.txt" encoding="utf-8";
put _all_;
run;

The Text File of the class data set from SASHELP center is:

Export SAS dataset into TXT file with encoding UTF8 option

Sum it up: We have discussed the 2 quick ways to export SAS data as CSV files. The first method, PROC EXPORT procedure, is easy to use; however, we cannot encode the data.

8. More related readings:

Import Excel, TEXT, STATA file into SAS

Advertisements

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

Advertisements