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 3 weeks ago - edited 3 weeks ago (1,736 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";



/* 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*/
dbms=csv replace;

%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:





Next, write the Libname statement:




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"




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








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";



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 )*/


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





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:






Here is the CSV file SAS University Edition created:







Comment below if you have any questions or concerns.