DATA Step, Macro, Functions and more

Handling Line breaks in csv

Posts: 21

Handling Line breaks in csv

Hi All,

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?

Like this:

infile &file12 dlm='09'x dlm = ',' MISSOVER DSD ;

(I have given a macro for file name which is working perfectly fine)

Kindly suggest.

Thanks & regards,


Super Contributor
Posts: 644

Re: Handling Line breaks in csv

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

Super Contributor
Posts: 644

Re: Handling Line breaks in csv

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 ;

run ;

NOTE: The file 'C:\Users\Public\Temp\test.txt' is:

      File Name 'C:\Users\Public\Temp\test.txt',

      Lrecl=256, Recfm=V

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)

Respected Advisor
Posts: 3,777

Re: Handling Line breaks in csv

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.

Super User
Posts: 9,676

Re: Handling Line breaks in csv

There are two ways :

infile datalines dlm='2C09'x  MISSOVER DSD;

2C is hex value of comma ,or

infile datalines dlm=', ' expandtabs;


Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation