06-26-2017 12:45 PM
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.
06-26-2017 01:44 PM
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 ....;
06-28-2017 01:33 PM
06-28-2017 02:47 PM - edited 06-28-2017 02:49 PM
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.