Help using Base SAS procedures

Export from SAS to TXT file and keep structrure

Reply
Frequent Contributor
Posts: 136

Export from SAS to TXT file and keep structrure

Hello

I am trying to export a sas data set to txt file.

proc export data=sashelp.class outfile="/usr/local/SAS/xxxlexample.txt"      dbms=tab replace;
putnames=no;
run;

 

When I open the  txt file i see that all data is in one row.

I want to export the data and keep same table structure as in original data set.

 

Thanks

Ronekd

Super User
Super User
Posts: 9,599

Re: Export from SAS to TXT file and keep structrure

Define "When I open the  txt file i see that all data is in one row." please.  Are you exporting the file on a Unix system and opening on a Windows system?  This is the most common cause of confusion as Unix and Windows line endings are different.  Notepad cannot cope with that, but Notepad++ and Textpad for example can,  and the data is importable in either by use of the termstr modifier.

 

Otherwise please clarify how your getting the file, and what your opening it with.

Frequent Contributor
Posts: 136

Re: Export from SAS to TXT file and keep structrure

One row means that all data is in one raw

For example:

lets say we have 2 observations with 2 fields

Normal table structure is:

1  10 

2   5  

And I get

1  10  2   5

 

 

 

 

Super User
Super User
Posts: 9,599

Re: Export from SAS to TXT file and keep structrure

know what you mean.  What you don't know is that the raw ascii underneath that includes one or two special characters called LF (linefeed) and CR (carriage return) which tells the program when yo break the line.  Unix only uses LF, windows uses LF+CR.  If you transfer your file from Unix to Windows, and use a program which cannot understand this such as notepad, then the program sees LF and thinks, thats not a line ending I will ignore it.

If you want further help, tell us how your exporting - which os as wel, which os your opening on, how your transferring, and what application to open it.

Super User
Posts: 23,681

Re: Export from SAS to TXT file and keep structrure


@Ronein wrote:

Hello

I am trying to export a sas data set to txt file.

proc export data=sashelp.class outfile="/usr/local/SAS/xxxlexample.txt"      dbms=tab replace;
putnames=no;
run;

 

When I open the  txt file i see that all data is in one row.

I want to export the data and keep same table structure as in original data set.

 

Thanks

Ronekd


This is likely an artifact of how you're seeing the data, but it should be fine. 

Make sure your text editor has word wrap turned on or try and open it with Excel to see if it's properly formatted. 

 

Otherwise, if you're transferring files from Unix to Windows, the end of line character for Unix is ...

 

Your exact code worked fine for me. 

 

delete_export.PNG

 

Try explicitly setting the end of line character using TERMSTR.

 


filename myout "C:\_localdata\temp\xxxlexample.txt" termstr=CRLF;
proc export data=sashelp.class outfile=myout      dbms=tab replace;
putnames=no;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 134 views
  • 0 likes
  • 3 in conversation