- About CISER Computing
- Computing Resources
- Request a CISER Computing Account
- Computing Node Availability and Usage
- Computing News & User Notes
- HelpDesk Services
- CISER Computing Basics
- CISER Computing FAQ
- CISER Billing FAQ
- Workshop Downloads
- Workshop Schedules & Registration
- Software on the Computing Nodes
- Online Help for Statistical Software
- Buying Statistical Software at Cornell
Writing a SAS Dataset To a Text File
Q. What's an easy was to write a small SAS data set to a space-delimited or a comma delimited text file?
A. To write a SAS data set to a text file use a DATA step with a FILE statement and a PUT statement. In your FILE statement use the option DLM= to specify a delimiter for the output text file (Note: Output that contains embedded delimiters requires the DSD option). The SAS uses a single space as the default delimiter. (Caution: If your SAS data set includes non-numeric variables with missing values, do not use a space as the output ascii data delimiter.) Examples are given below.
To Create a Space Delimited Text File:
libname ssd '[drive]:\[your_folder]\proj\' ;
data _null_ ; /* No SAS data set is created */
set ssd.income ;
FILE '[drive]:\[your_folder]\rawfile.txt' ; /* Output Text File */
PUT var2 var3 var1 var4 var5 ;
run ;
To Create a Comma Delimited Text File:
libname ssd '[drive]:\[your_folder]\proj\' ;
data _null_ ; /* No SAS data set is created */
set ssd.income ;
FILE '[drive]:\[your_folder]\rawfile.txt' DLM=',' ; /* Output Text File */
PUT var5 var2 var3 var1 var4 ;
run ;
You can also use SAS Export Wizard to create a delimited
ascii file from a SAS data set. To use the wizard, create a SAS data library
and then click on FILE -> Export
Data.