We’re smarter together. Learn from this collection of community knowledge and add your expertise.

How to Export SAS Datasets as a .CSV File in SAS University Edition

by Community Manager ‎03-02-2018 09:18 AM - edited ‎03-02-2018 09:18 AM (3,046 Views)

Following are two simple ways to convert/export SAS dataset files (.sas7bdat extension) into a comma-separated values dataset (.csv extension) in SAS University Edition.

 

Method #1:

Use snippets to convert a SAS dataset into a .CSV file

 

SAS University Edition makes it easier than ever to convert from a SAS dataset into a .CSV file by using snippets! 

 

Code used:

 

libname example "/folders/myfolders";

run;

 

/* Stream a CSV representation of SASHELP.CARS directly to the user's browser. */

proc export data=example.ExampleData /* Rename the data= statement to include your Library.Dataset*/
outfile=_dataout
dbms=csv replace;
run;

%let _DATAOUT_MIME_TYPE=text/csv;
%let _DATAOUT_NAME=ExampleData.csv; /* Be sure to rename the CSV file here*/

 

 

Let's say I want to convert the following SAS Dataset file into a CSV file:

 

Export to CSV.png

 

First, I have to write a Library Name (Libname) statement to reference the file containing the dataset that I would like to convert.

To write the Libname statement, I need to find the folder path of the library. Right click on the folder containing the dataset and click properties to view the path of the folder:

 

 findPath.png

path.PNG

 

Next, write the Libname statement:

 

libraryName.png

 

Then, on the left hand side of the screen find the tab labeled "Snippets", and click on it. Then, click on the subheading under Snippets titled "Snippets"-->"Data"-->"Generate CSV File"

 

GenerateCSV.png

 

It will generate a default Snippet to generate a CSV file that you must edit.

 

Default:

defaultSnippet.png

 

Edited:

SnippetEdited.png

  

Click Run and you should see a prompt on Microsoft Excel to open the CSV file that you just created!

 

 

Method #2: 

Use a generic PROC EXPORT statement

 

Code used:

 

libname example "/folders/myfolders";

run;

 

proc export data=example.ExampleData
outfile='/folders/myfolders/ExampleCSV.csv' /*Use the same path as above, adding a forward slash and the name of
your file.csv ( /ExampleCSV.csv )*/
dbms=csv
replace;
run;

 

Rather than using the snippet, using the proc export statement allows you to specify an output CSV file location:

 

BetterWay.png

 

 

As you can see, the program runs and the CSV is output into my "My Folders" folder in the Server Files and Folders tab in SAS Studio:

 

Success.png

 

 

 

Here is the CSV file SAS University Edition created:

 

 

 

CSVFIle.png

 

 

Comment below if you have any questions or concerns.