Hello everyone,
I have a SAS code works well in PC environment. the SAS code does some text/flat file read and write.
But when I move it to unix. it casuse error. the reason is there are unexpected ^M at end of each rows (Enter Key). which cause error when I tried to do some string operation.
These ^M are invisible for windows notepad but visible for Unix vi editor.
Please help!
Thanks!
Can you run the "dos2unix" facility on the files in Putty or some equivalent?
Have you tried specfying a TERMSTR type on your FILE statement?
How did you move the text files between the two environments? If you use FTP with ASCII mode then it should transform the CR+LF that DOS/WIndows uses as end of line into the LF that Unix uses as end of line.
If you are editing the files using NOTEPAD on a PC you might want to switch to using WORDPAD instead since it can handle text files with just LF as the end of line.
How are you reading the files in SAS?
You try adding the TERMSTR=CRLF to the appropriate INFILE, FILE or FILENAME statements to force all files in and out to use the DOS end of line convention.
But if you live in a mixed environment where PC and Unix users/apps are both reading and writing files to the same physical disk then you might need to make your input steps more flexible to handle files that have either format.
One idea is if you are reading the files are delimited files is to add the CR to the list of delimiters.
dlm=','||'0d'x;
infile 'myfile.txt' dsd dlm=dlm truncover firstobs=2;
Another is to add code to remove the CR from the line before running the INPUT statement.
input @;
_infile_ = compress(_infile_,'0d'x);
input ....;
@GeorgeSAS wrote:
Now here is a new problem: If I want 'FILE' a flat/text file from UNIX? I want the output file with Carriage Returns.
You can add the TERMSTR=CRLF option to the FILE statement or FILENAME statement and SAS will write lines with both CR and LF at the end of the lines, which is the format that DOS/WIndows uses.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.