BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kisumsam
Quartz | Level 8

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 🙂

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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. 🙂

 

 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

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.

 

 

ChrisNZ
Tourmaline | Level 20

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. 🙂

 

 

 

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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