10-31-2012 04:07 AM
I want to import a csv file in SAS.
The problem is that, it contains line breaks and it is causing errors.
My question is, can we use dlm = '09'x and dlm = ',' together in one statement?
infile &file12 dlm='09'x dlm = ',' MISSOVER DSD ;
(I have given a macro for file name which is working perfectly fine)
Thanks & regards,
10-31-2012 04:45 AM
You would use dlm = '09'x if the file were tab delimited. If the file is comma delimited use the comma only.
Line breaks at end of data lines are normal for Windows and Unix
I have not had time to test it, but changing MISSOVER to FLOWOVER might work if SAS is detecting multiple line breaks
Can you post some sample lines where you have the problem?
Also, which operating system are you working in and was the data copied from another system.
Does your data have headers?
Richard in Oz
10-31-2012 05:02 AM
If your data has blank lines like the test set below this fix might work for you. Note use of FLOWOVER and no DSD
1, 2, 3
4, 5, 6
7, 8, 9
data test ;
infile 'C:\Users\Public\Temp\test.txt' dlm=',' FLOWOVER ;
input A B C ;
NOTE: The file 'C:\Users\Public\Temp\test.txt' is:
File Name 'C:\Users\Public\Temp\test.txt',
NOTE: 4 records were read from file 'C:\Users\Public\Temp\test.txt'
The minimum record length was 0
The maximum record length was 7
NOTE: A new line was read when INPUT statement read past the end of a line
NOTE: Data set "WORK.test" has 3 observation(s) and 3 variable(s)
10-31-2012 07:16 AM
You need to more specific about "line breaks".
In my limited experience CSVs created by XL can have '0A'x as a result of the use of alt-enter in XL.
You should be able to use the INFILE statement option TERMSTR=CRLF which "should" fix the problem.
If you are still using SAS 9.1 I don't this this worked in that version of SAS.