Help using Base SAS procedures

Importing a csv file in SAS, multilines problem

Reply
Frequent Contributor
Posts: 75

Importing a csv file in SAS, multilines problem

hi all,

so I need to import a csv file, delimited by ; , to a sas data set.

heres an idea of the data:

aaa; bbb; ccc

xxx; yyy; zzz

ppp; jjj; aaaaa...

...aaaa

so, in the third abservation, the variable is long so that it goes to the next line of the csv file.

when I write some simple import proc like the below, it recognizes these new lines as new variables.

proc import

    datafile = "have.csv"

    out = test

    dbms = csv;

    delimiter = ";";

    getnames=no;

    run;

Anyone has a suggestion for taking care of that multi-line observations? really appreciate it!

Occasional Contributor
Posts: 13

Re: Importing a csv file in SAS, multilines problem

Hey Shayan,

     Please use the below code and check.

data XYZ ;

infile "have.csv" DLM=';';

length filename$ 500;

input filename@@ ;

;

run;

Super User
Super User
Posts: 7,407

Re: Importing a csv file in SAS, multilines problem

Hi,

Can I check, do you mean that the line in your text editor just wraps due to space limitations in the editor, or that there is actually embedded line break codes within that data.  The way to do this is to use a free Hex editor (Google, there is lots of free ones), goto a place where you know there is a break and look at the actual Hex code where the line splits.  If you see 0A0D or similar then you have more problems than just a long string.  Have a look at my post here: https://communities.sas.com/thread/60374

Where I have some correspondence with Tech Support.

If its just a long of text (and why would you have text that long anyways?) something like GokulShivananda has posted would be suggested.  As always I would avoid the use of proc import at all.  Write the code yourself and you know what your data looks like and what you want, proc import is all guess work.  If you have further problems with the code above, remember the infile options - lrecl, dsd, missover etc.

Super User
Posts: 9,682

Re: Importing a csv file in SAS, multilines problem

You should throw proc import away under this situation. use recfm=n to take it as a stream file.

filename x 'c:\temp\have.txt';
data have;
infile x DLM=';' recfm=n;
length filename$ 500;
input filename@@ ;
run;

Xia Keshan

Ask a Question
Discussion stats
  • 3 replies
  • 423 views
  • 3 likes
  • 4 in conversation