DATA Step, Macro, Functions and more

What use is the delimiter option in the INFILE statement?

Reply
Frequent Contributor
Posts: 107

What use is the delimiter option in the INFILE statement?

[ Edited ]

Does it do anything? It seems to ignore it and treat my delimited file as a flat file.

Super User
Posts: 24,026

Re: What use is the delimiter option in the INFILE statement?

Posted in reply to tomcmacdonald

tomcmacdonald wrote:

Does it do anything?

 

Yes. 

 


tomcmacdonald wrote:

It seems to ignore it and treat my delimited file as a flat file.


You're using it incorrectly then. 

Frequent Contributor
Posts: 107

Re: What use is the delimiter option in the INFILE statement?

Why does it bleed over into the other column?  Doesn't SAS know to stop when it hits the delimiter? 

Super User
Posts: 24,026

Re: What use is the delimiter option in the INFILE statement?

Posted in reply to tomcmacdonald

tomcmacdonald wrote:

Doesn't SAS know to stop when it hits the delimiter? 


That's what it does. Like I said, you're likely doing something wrong. You need to show your code, log and ideally sample data that reflects your situation

Frequent Contributor
Posts: 107

Re: What use is the delimiter option in the INFILE statement?

I just find the fact that it's bleeding over to be pretty bizarre.  You figure SAS would throw an error at least.

Super User
Posts: 10,616

Re: What use is the delimiter option in the INFILE statement?

Posted in reply to tomcmacdonald

If SAS can do what you tell it to do, there's no reason to throw an error. And there are valid reasons for mixing list and formatted input (I guess that is the reason for your problem) at certain times.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,946

Re: What use is the delimiter option in the INFILE statement?

Posted in reply to tomcmacdonald

tomcmacdonald wrote:

Why does it bleed over into the other column?  Doesn't SAS know to stop when it hits the delimiter? 


Show your log where you run the code Preferably in a code box opened with the forum's {I} icon. Also best would be to provide some example of the data file. Do not paste your data example into the main window but use a code box. The main message windows reformat pasted text.

 

there are potentially lots of interactions but the one I see here most frequently that sounds like what you describe is placing a format as part of the INPUT.

 

If you have

input var $10. it will read 10 characters pretty much.

 

informat var $10. ;

input var;

will read var as charcter up to the first delimiter if the infile is declared with the correct delimiter.

Other options such as DSD also have an impact.

Super User
Posts: 13,946

Re: What use is the delimiter option in the INFILE statement?

Posted in reply to tomcmacdonald

tomcmacdonald wrote:

Why does it bleed over into the other column?  Doesn't SAS know to stop when it hits the delimiter? 


Please look at these code examples. Does your code look at all like the first one?

Note that the values of x and y vary between the two sets because the second is one preferred way to specify informats that respect delimiters;

data example;
   infile datalines dlm=',';
   length x $ 5;
   informat y z $5.;
   /* a format on an input statement ignores the 
    delimiter because you are forcing a read of 5 columns
   */
   input x $5.  y z;
datalines;
123,abcd,fghijk
;
run;
data example2;
   infile datalines dlm=',';
   length x y z $5.;
   input x  y z;
datalines;
123,abcd,fghijk
;
run;
Ask a Question
Discussion stats
  • 7 replies
  • 175 views
  • 1 like
  • 4 in conversation