BookmarkSubscribeRSS Feed
ShaheenRanalvi
Calcite | Level 5

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,

Shaheen

5 REPLIES 5
RichardinOz
Quartz | Level 8

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

RichardinOz
Quartz | Level 8

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)

anujyadav7547
Calcite | Level 5

I had a similar problem.

My data was a free text survey data and was in CSV format(comma delimited).

Changing MISSOVER to FLOWOVER did the trick. 

 

Thanks everyone

data_null__
Jade | Level 19

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.

Ksharp
Super User

There are two ways :

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

2C is hex value of comma ,or

infile datalines dlm=', ' expandtabs;

Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 7141 views
  • 0 likes
  • 5 in conversation