BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

 

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;

 

9 REPLIES 9
collinelliot
Barite | Level 11

If there are spaces between the two fields, why are you using a tab ('09'x) as the delimiter?

mlogan
Lapis Lazuli | Level 10
What should I use collinelliot?
cau83
Pyrite | Level 9

Use a data step instead, something like:

filename fileref 'filepath';

data test;
   infile fileref;
   input student_id 1-8 call_id $ 32-48;
run;

If that blank row is there, you could add a 'if _n_<=2 then delete;'

 

art297
Opal | Level 21

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;

HTH,

Art, CEO, AnalystFinder.com

 

mlogan
Lapis Lazuli | Level 10

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?

art297
Opal | Level 21

See my post above. Just make sure that the lengths set in the informats are long enough.

 

Art, CEO, AnalystFinder.com

cau83
Pyrite | Level 9

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.

Ksharp
Super User
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;
Kurt_Bremser
Super User

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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1247 views
  • 1 like
  • 6 in conversation