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
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
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)
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
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.
There are two ways :
infile datalines dlm='2C09'x MISSOVER DSD;
2C is hex value of comma ,or
infile datalines dlm=', ' expandtabs;
Ksharp
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.