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

8 Responses

  1. In 1998, Edwards and Clarke donated the contents of Bacon’s studio at 7 Reece Mews, London, left untouched since Bacon’s demise, to the Hugh Lane, the Dublin City Gallery.

  2. With every thing that seems to be building inside this subject material, your points of view happen to be fairly radical. Even so, I am sorry, because I do not subscribe to your entire theory, all be it radical none the less. It would seem to me that your commentary are generally not completely rationalized and in simple fact you are generally yourself not really completely confident of your argument. In any event I did enjoy reading it.

  3. Thanks for your submission. I would love to say that the very first thing you will need to carry out is check if you really need credit repair. To do that you have got to get your hands on a replica of your credit file. That should never be difficult, ever since the government makes it necessary that you are allowed to receive one no cost copy of your actual credit report each year. You just have to consult the right men and women. You can either find out from the website for your Federal Trade Commission as well as contact one of the leading credit agencies directly.

Leave a Reply

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

Advertisements