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

 

Hi,

I'm working with a program to create a text file. It works fine but it doesn't go to the next line for the next obs and it continues with

the same line. How can I create a text file that in each row shows one record(obs)?

 

Here is my code:

data _null_ ; 
set table.abc;
FILE '/opt/sas94/home/user1/text1.txt' dsd dlm=',' ; 
PUT var1 var2 var3 var4 var5 var6 var7 var8;
run ;

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You shouldn't put a | between them.  The line is terminated by a given line terminator - so long as the person importing the file knows the line terminator, they can read it in correctly.  See this article for the process:
http://support.sas.com/kb/14/178.html

 

And for more information on this topic:

https://en.wikipedia.org/wiki/Newline

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What are you opening the file in to view the data?  The reason is I run this on my SAS:

data _null_; 
  set sashelp.class; 
  file 'c:\test.csv' dsd dlm=','; 
  put name sex age; 
run ;

And it works fine when I open it in Notepad.  Do note the consistent code formatting, indetation and the use of code editor {i} above your post.  Note also that I call the output file .csv, this is because you are creating a Comma Separated Variable file, so make sure the file extension describes the data correctly.


What I suspect is your opening that data in either A) a package that doesn't interpret line feed/break characters, or B) your moving it across to Windows from Unix - this is most likely and common.  Windows and Unix have different CR/LF special characters which indicate the end of line.

Riana
Pyrite | Level 9

Thank you RW9 for your reply.

I'm opening the text file in Notepad. I've corrected my code by using pipe '|' as delimeter. This file should be sent as text file:

data _null_ ; 
set table.abc;
FILE '/opt/sas94/home/user1/text1.txt' dsd dlm='|' ; 
PUT var1 var2 var3 var4 var5 var6 var7 var8;
run ;

B) your moving it across to Windows from Unix - this is most likely and common.

Yes,maybe it is the issue. There are two ways  for me to run the code:

  • Localy from my PC and connect to the server and save text file there.
  • From Citrix (Windows server) and save file on server.

In both cases I faced the same problem but it seems that it is OK for my colleague to receive the file in this way.

But I have another question. Here is an example of text file:

 

 

100000095|abcdefghijk|kj7764bbid|20JAN2015|21FEB2015|201501100000098|abcdefncvbjk|abcdehg564d5|09JAN2015|02APR2015|201501100000096

In 201501100000098, 201501 is the last value for the first record and 100000098 is the first value for the second record.

How should I change the code so '|' to be placed between 201501 and100000098?

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You shouldn't put a | between them.  The line is terminated by a given line terminator - so long as the person importing the file knows the line terminator, they can read it in correctly.  See this article for the process:
http://support.sas.com/kb/14/178.html

 

And for more information on this topic:

https://en.wikipedia.org/wiki/Newline

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2713 views
  • 0 likes
  • 2 in conversation