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
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:
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.
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:
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?
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:
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.