02-16-2017 03:34 PM - edited 02-16-2017 03:44 PM
Student_ID Call_ID 09008767 02541-027-0415471 09149065 04531-027-8565478 09597360 04531-027-2546587
I have the above table in a .txt file. I want to import as sas dataset. My following code is not working. Can someone help me please. Please note that there are 23 character space between first two values and 14 space between 2nd and 3rd value (I have 9 variables total in the dataset). I am getting the following error message.
NOTE: The quoted string currently being processed has become more than 262 characters long. You
might have unbalanced quotation marks.
proc import datafile='R:\have.txt' out=test dbms=dlm replace; delimiter='09'x; run;
02-16-2017 03:44 PM - edited 02-16-2017 03:48 PM
Use a data step instead, something like:
filename fileref 'filepath'; data test; infile fileref; input student_id 1-8 call_id $ 32-48;
If that blank row is there, you could add a 'if _n_<=2 then delete;'
02-16-2017 03:45 PM
Or, rather than worrying about the specific column locations:
data want; infile '/folders/myfolders/have.txt' firstobs=3; informat Student_ID $8.; informat Call_ID $17.; input Student_ID Call_ID; run;
Art, CEO, AnalystFinder.com
02-16-2017 03:52 PM
I just noticed that each of my variable has different lengths with different space length in between. Is there a way I can import them without defining the character space. Like something that we do in imorting from Excel?
02-16-2017 04:05 PM
Depending on the variability... sometimes I cave and bring it all in as one giant field and then split with data step functions. For instance, if sometimes the first column value length is so long that it spills over to what is sometimes the 2nd column, then even specifying lengths on the informat isn't foolproof. So instead I (not saying it's the best way, just the crutch iI go to):
data test; infile; input BIG_VAR $ 1-250; var1=strip(scan(big_var,1," ")); var2=strip(scan(big_var,2," ")); run;
Assuming that there are no spaces within the fields, this should split it up and then the strip function will get rid of the leading/trailing blanks I believe.
02-16-2017 08:59 PM
1)Try Arthur.T 's code and add one more option. data want; infile '/folders/myfolders/have.txt' firstobs=3 expandtabs; informat Student_ID $8.; informat Call_ID $17.; input Student_ID Call_ID; run; 2)Try another engine. proc import datafile='R:\have.txt' out=test dbms=tab replace; run;
02-17-2017 06:03 AM
Why use proc import at all with such an easy structure?
I copy/pasted your text data into a UNIX text file and ran the following:
data test; infile '$HOME/sascommunity/test.txt' firstobs=3; length student_id $8 call_id $17; input student_id call_id; run; proc print data=test noobs; run;
This is the result:
student_ id call_id 09008767 02541-027-0415471 09149065 04531-027-8565478 09597360 04531-027-2546587