01-18-2013 06:01 AM
I'm reading in csv files on the UNIX and using the TERMSTR option in the file statement ( link SAS(R) 9.2 Companion for UNIX Environments)
filename csvfile " /projx/file1.csv" termstr=CRLF;
infile "csvfile" firstobs=2 dlm=',' dsd missover;
input projectid $100.;
controls the end-of-line or record delimiters in PC- and UNIX-formatted files. This option enables the sharing of UNIX- and PC-formatted files between the two hosts. The following are values for the TERMSTR= option:
This works well and do not need to convert the files from PC to unix or vice versa when reading them in. But to avoid changing the code if we receive files in the other format next time it would be good to see if the SAS program can work out which environment the file if from and then use the option or not.
01-18-2013 07:36 AM
Did you consider just running DOS2UNIX on the files?
This will not work for TERMSTR=CR.
01-18-2013 07:09 PM
What data _null_ said.
As the saying goes "If the only tool you own is a hammer, everything starts to look like a nail". Other than as an academic exercise in SAS, why don't you just ensure that your input files are in Unix format?
Google "sed convert dos to unix". This was the first hit: HowTo: UNIX / Linux Convert DOS Newlines CR-LF to Unix/Linux Format
Also, if you're FTPing the files from Windows to Unix and vice versa, make sure you transfer text files as TEXT not BINARY. The FTP protocol will handle converting the line terminators to the correct value for the given operating system. If you're using an FTP client, add .CSV, .SAS, .LOG, .LST, etc to the list of filename extensions that are considered text files.
Hope this helps,
01-19-2013 03:45 AM
a solution that works with both unix and windows line endings is to extend the DLM= option to include '0D'x
the normal line ending on unix is just '0A'x and on windows '0D0A'x so the only problem is that 0D.
01-23-2013 09:32 AM
Thanks for this. So do I need to change the DLM= value each time the file changes or can I use a DLM value which will work with both formats?
01-23-2013 06:29 PM
for any infile statement that refers to files from either environment you can specif DLM='0d20'x
(assuming space is 20x)
It seems very unlikely that DLM type input would ever have a 0Dx that must be treated as data
On windows the environment would eat that 0Dx and on unix, it would be treated like a space delimiter (at the end of a line this would have no impact).
So on both unix and on windows platforms DLM='0D20'x will achieve what you need.
give it a try
01-23-2013 09:25 AM
Being a traditionalist....I did not want to change the files we got to read in from the client. Sure I could convert the files but would rather keep them in their original state. I thought there may be a way to tell if a file was windows or unix based.
01-23-2013 10:41 AM
I thought there may be a way to tell if a file was windows or unix based.
Hello, I showed you the code you need above. It reads one record and creates a TERMSTR macro variable.