DATA Step, Macro, Functions and more

Tab delimiter error with Datalines

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 80
Accepted Solution

Tab delimiter error with Datalines

[ Edited ]

Hello,

 

I have a very basic question.  Why does this code not work?  The spaces between the numbers in the datalines below are tabs.  I'm using SAS 9.4 on Windows 7 64-bit.

 

data a;
	infile datalines dlm = '09'x dsd truncover;
	input a b c d e;
	datalines;
1	2	3	4	5
2	3		5	6
3			6	7
4	5	6	7
;
run;

 

If I omit both the dlm = '09'x and the dsd options, it runs, but gives incorrect results, viewing two or more delimiters as just one.

If I add only dsd, it doesn't seem to register any delimiters at all, and views each row as one 17-character long text string.

If I add only dlm = '09'x, it also doesn't recognize any delimiters and views each row as one 80-character long text string.

If I add both, it treats it the same as only dsd.

 

Am I using the wrong code to define a tab delimiter?  Using a separate file work.  The issue is only with DATALINES.  Any help would be appreciated.

 

152878  data a;
152879      infile datalines /*dlm = '09'x dsd*/ truncover;
152880      input a b c d e;
152881      datalines;

NOTE: The data set WORK.A has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


152886  ;
152887  run;

152888  data a;
152889      infile datalines /*dlm = '09'x*/ dsd truncover;
152890      input a b c d e;
152891      datalines;

NOTE: Invalid data for a in line 152892 1-17.
RULE:         ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
152892        1   2   3   4   5
a=. b=. c=. d=. e=. _ERROR_=1 _N_=1
NOTE: Invalid data for a in line 152893 1-17.
152893        2   3       5   6
a=. b=. c=. d=. e=. _ERROR_=1 _N_=2
NOTE: Invalid data for a in line 152894 1-17.
152894        3           6   7
a=. b=. c=. d=. e=. _ERROR_=1 _N_=3
NOTE: Invalid data for a in line 152895 1-13.
152895        4   5   6   7
a=. b=. c=. d=. e=. _ERROR_=1 _N_=4
NOTE: The data set WORK.A has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


152896  ;
152897  run;

152898  data a;
152899      infile datalines dlm = '09'x /*dsd*/ truncover;
152900      input a b c d e;
152901      datalines;

NOTE: Invalid data for a in line 152902 1-80.
RULE:         ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
152902        1   2   3   4   5
a=. b=. c=. d=. e=. _ERROR_=1 _N_=1
NOTE: Invalid data for a in line 152903 1-80.
152903        2   3       5   6
a=. b=. c=. d=. e=. _ERROR_=1 _N_=2
NOTE: Invalid data for a in line 152904 1-80.
152904        3           6   7
a=. b=. c=. d=. e=. _ERROR_=1 _N_=3
NOTE: Invalid data for a in line 152905 1-80.
152905        4   5   6   7
a=. b=. c=. d=. e=. _ERROR_=1 _N_=4
NOTE: The data set WORK.A has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


152906  ;
152907  run;

152908  data a;
152909      infile datalines dlm = '09'x dsd truncover;
152910      input a b c d e;
152911      datalines;

NOTE: Invalid data for a in line 152912 1-17.
RULE:         ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
152912        1   2   3   4   5
a=. b=. c=. d=. e=. _ERROR_=1 _N_=1
NOTE: Invalid data for a in line 152913 1-17.
152913        2   3       5   6
a=. b=. c=. d=. e=. _ERROR_=1 _N_=2
NOTE: Invalid data for a in line 152914 1-17.
152914        3           6   7
a=. b=. c=. d=. e=. _ERROR_=1 _N_=3
NOTE: Invalid data for a in line 152915 1-13.
152915        4   5   6   7
a=. b=. c=. d=. e=. _ERROR_=1 _N_=4
NOTE: The data set WORK.A has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.03 seconds


152916  ;
152917  run;

Accepted Solutions
Solution
‎10-11-2016 10:28 AM
Respected Advisor
Posts: 3,777

Re: Tab delimiter error with Datalines

The problem is DMS.  When you click run the editor or the submitter or something is expanding the tables.  If you run in EG or batch it will work. 

 

You may want to check options to figure is you can change that behavior.

View solution in original post


All Replies
Contributor
Posts: 55

Re: Tab delimiter error with Datalines

Is it possible that your delimiter in your datalines is actually consecutive spaces and not a true TAB?

 

When I copy your syntax and insert in tabs myself.. the version using dlm='09'x (the true TAB unicode character) works.

When I replace those tabs with spaces and run using dlm='09'x, I get the same errors you are describing.

 

So it seems to me that your session is interpreting what you think are TABs as just consecutive spaces.

 

I don't have access to SAS running on Windows 64.. I am testing on SAS EG running on a Linux server, but nonetheless that is what I'm seeing.

Frequent Contributor
Posts: 123

Re: Tab delimiter error with Datalines

[ Edited ]

When I copy your code into SAS EG it works. Why not just replace all tabs with a space and then run this?

 

data a;
 infile datalines dlm=' ' dsd truncover;
 input a b c d e;
 datalines;
1 2 3 4 5
2 3  5 6
3   6 7
4 5 6 7
;
run;

Are you using SAS Enterprise Guide? Sometimes it can interpret tabs as characters and the data doesn't get read in as expected. If you're in SAS EG, go to tools->options->SAS Programs->Editor Options and uncheck the "Replace tabs with spaces on file open" if it is checked. Then re-open the file and rerun. This may be the issue.

Super User
Posts: 3,113

Re: Tab delimiter error with Datalines

Why not keep it simple? There is no good reason to use tabs with datalines as they are not visible in the program. Just use column-style input. 

Solution
‎10-11-2016 10:28 AM
Respected Advisor
Posts: 3,777

Re: Tab delimiter error with Datalines

The problem is DMS.  When you click run the editor or the submitter or something is expanding the tables.  If you run in EG or batch it will work. 

 

You may want to check options to figure is you can change that behavior.

Super User
Posts: 10,538

Re: Tab delimiter error with Datalines

It may not hurt to try putting . for the missing values.

 

data a;
	infile datalines  truncover;
	input a b c d e;
	datalines;
1	2	3	4	5
2	3	.	5	6
3	.	.	6	7
4	5	6	7       .
;
run 

to simplify list style input.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 490 views
  • 2 likes
  • 6 in conversation