BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kastchei
Pyrite | Level 9

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;
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

5 REPLIES 5
JoshB
Quartz | Level 8

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.

JediApprentice
Pyrite | Level 9

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.

SASKiwi
PROC Star

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. 

data_null__
Jade | Level 19

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.

ballardw
Super User

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.

 

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
  • 5 replies
  • 7983 views
  • 2 likes
  • 6 in conversation