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!
Hey Shayan,
Please use the below code and check.
data XYZ ;
infile "have.csv" DLM=';';
length filename$ 500;
input filename@@ ;
;
run;
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.
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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.