Hi,
I'm trying to import a comma delimited txt file into SAS and this is the code I'm using:
proc import datafile='U:\DICA raw data.txt' dbms=dlm out=DICA_new replace;
delimiter=","; getnames=no; datarow=1 ;
r
I'm ending up with an output of the first 1171 variables, but my data has around 1800. How do I keep it from cutting off the rest of the columns?
example of what my data looks like:
"3","","1","","2","1","3","0","0","0","0","0","0","","0","","CNT","0","1","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",
1) Don't use PROC IMPORT. Just read the file using a data step.
data DICA_new ;
infile 'U:\DICA raw data.txt' dsd truncover lrecl=30000 ;
length var1-var1800 $40 ;
input var1-var1800 ;
run;
2) Don't create the file with all of those unneeded quotes. Then perhaps the lengths of the lines will be small enough for PROC IMPORT to read. You can convert it using a simple data step.
data _null_
infile 'U:\DICA raw data.txt' dsd truncover lrecl=30000 col=cc length=len ;
input @;
length s $200;
file 'U:\DICA_fixed.txt' dsd lrecl=30000 ;
do until(cc >= len);
input s @;
put s @;
end;
put;
run;
Your example data line "fixed" by removing the unneeded quotes is much shorter.
3,,1,,2,1,3,0,0,0,0,0,0,,0,,CNT,0,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1) Don't use PROC IMPORT. Just read the file using a data step.
data DICA_new ;
infile 'U:\DICA raw data.txt' dsd truncover lrecl=30000 ;
length var1-var1800 $40 ;
input var1-var1800 ;
run;
2) Don't create the file with all of those unneeded quotes. Then perhaps the lengths of the lines will be small enough for PROC IMPORT to read. You can convert it using a simple data step.
data _null_
infile 'U:\DICA raw data.txt' dsd truncover lrecl=30000 col=cc length=len ;
input @;
length s $200;
file 'U:\DICA_fixed.txt' dsd lrecl=30000 ;
do until(cc >= len);
input s @;
put s @;
end;
put;
run;
Your example data line "fixed" by removing the unneeded quotes is much shorter.
3,,1,,2,1,3,0,0,0,0,0,0,,0,,CNT,0,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Unlike Tom. I think you should use proc import , use filename to tell SAS that file 's lrecl is very very long.
filename x 'U:\DICA raw data.txt' lrecl=300000;
proc import datafile=x dbms=dlm out=DICA_new replace;
delimiter=","; getnames=no; datarow=1 ;
run;
Xia Keshan
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 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.