Learning SAS? Welcome to the exclusive online community for all SAS learners.

export to a text file

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

export to a text file

Hi, I have a dataset with 100 records. I'd like write it to a text file with the following code.

data _null_;

set a1;

file '/folders/myshortcuts/MyFolders/b.txt' DSD DLM='09'X;

put i;

run;

The b.txt is successfully created. However, it puts all 100 records into 1 line/record, rather than 100 lines.

Any solution to that?

Thanks


Accepted Solutions
Solution
‎07-01-2015 01:41 AM
Super User
Posts: 6,969

Re: export to a text file

Notepad is Windows-only and expects CRLF as the line terminator, while SAS on the UNIX VM of SAS UE writes a UNIX text file that uses only the LF character as line terminator.

Solution #1: use TERMSTR=CRLF while creating the file

Solution #2: use Notepad++ or a similar editor that can work with CRLF and LF line terminators

I'd recommend Notepad++ anyway, as it offers many features useful to a developer.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 17,912

Re: export to a text file

Hmm...it shows up as separate lines for me. Possibly an issue with your editor? I am testing with SAS 9.3 though

New Contributor
Posts: 3

Re: export to a text file

I use notepad to open the text file

Learner
Posts: 1

Re: export to a text file

in your notepad format> word wrap enable the word wrap.

Solution
‎07-01-2015 01:41 AM
Super User
Posts: 6,969

Re: export to a text file

Notepad is Windows-only and expects CRLF as the line terminator, while SAS on the UNIX VM of SAS UE writes a UNIX text file that uses only the LF character as line terminator.

Solution #1: use TERMSTR=CRLF while creating the file

Solution #2: use Notepad++ or a similar editor that can work with CRLF and LF line terminators

I'd recommend Notepad++ anyway, as it offers many features useful to a developer.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
SAS Super FREQ
Posts: 361

Re: export to a text file

Gwong, yes, what KurtBremser said! Smiley Happy

PROC Star
Posts: 1,099

Re: export to a text file

Another option is that MS WORD will display the lines correctly.

Super User
Posts: 3,115

Re: export to a text file

Try the TERMSTR option on your FILE statement as discussed here:

14178 - INFILE's TERMSTR= option facilitates reading files betweenUNIX and Windows

You are creating a file in a Unix VM but reading the file in Windows with NOTEPAD. I don't have Unix to test but TERMSTR = LF will probably fix your problem.

New Contributor
Posts: 3

Re: export to a text file

Thanks all. TERMSTR=CRLF works perfect.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 532 views
  • 0 likes
  • 7 in conversation