DATA Step, Macro, Functions and more

Problem with Exporting Data to Text File using Put Statement

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Problem with Exporting Data to Text File using Put Statement

Hi, I got a problem when I tried to export data from a data set to a text file. I'm wondering if anyone can help Smiley Happy

 

So below is my code:

 

data _null_;
set sashelp.class;
file '/folders/myfolders/class.txt';
put name age height;
run;

 

 

I'm trying to export the name, age and height variables to a text file. The variables are from sashelp.class and I'm running the code on SAS Studio.

 

I'm expecting the data to be exported record by record. So if there are 19 records in sashelp.class, I am expecting the text file will have 19 records as well.

 

However, when I look at the text file, all the records stayed in one line. It looks like this:

 

Alfred 14 69Alice 13 56.5Barbara 13 65.3Carol 14 62.8Henry 14 63.5James 12 57.3Jane 12 59.8Janet 15 62.5Jeffrey 13 62.5

 

test.png

 

Does anyone know why?


Accepted Solutions
Solution
‎05-08-2017 07:06 AM
PROC Star
Posts: 1,759

Re: Problem with Exporting Data to Text File using Put Statement

As @Reeza said, you are reading a unix file under Windows.

Try:

data _null_;
  set SASHELP.CLASS;
  file '/folders/myfolders/class.txt' termstr=CRLF;
  put NAME AGE HEIGHT;
run;

and look up the reasons for this (minor) nonsense if you want. Smiley Happy

 

 

 

View solution in original post


All Replies
Super User
Posts: 19,770

Re: Problem with Exporting Data to Text File using Put Statement

Works fine for me. Check your Text Editor 'wrap text' option settings. 

 

Another possibility is since this was created on Unix it's using a Unix end of line character that the text editor isn't understanding. Turn on invisible characters to see what's happening there.

 

 

Solution
‎05-08-2017 07:06 AM
PROC Star
Posts: 1,759

Re: Problem with Exporting Data to Text File using Put Statement

As @Reeza said, you are reading a unix file under Windows.

Try:

data _null_;
  set SASHELP.CLASS;
  file '/folders/myfolders/class.txt' termstr=CRLF;
  put NAME AGE HEIGHT;
run;

and look up the reasons for this (minor) nonsense if you want. Smiley Happy

 

 

 

Super User
Posts: 7,762

Re: Problem with Exporting Data to Text File using Put Statement

Open the file with a more versatile tool like Notepad++. This will tell you the file type (UNIX) in the status line, and siplay the data correctly. To satisfy basic Windows software (like the simple Editor), use the termstr=CRLF option as @ChrisNZ suggested.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 156 views
  • 4 likes
  • 4 in conversation