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

Programe:

data pumpkin2;
infile "d:\sas\pumpkin2.txt";
input name & $16. age : 2. type : $1. date : mmddyy10. score1-score3 : 4.1;
run;

proc print data=pumpkin2;
format date mmddyy10.;
run;

ERROR :

NOTE: Invalid data for age in line 4 1-4.

NOTE: Invalid data for date in line 4 19-19.

NOTE: Invalid data for score1 in line 4 21-21.

NOTE: Invalid data for score2 in line 4 23-32.

RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-

4 Lori Newcombe 6 D 10-30-2003 6.7 5.6 4.9 5.2 6.1 52

name=Elizabeth Garcia age=. type=N date=. score1=. score2=. score3=6.7 _ERROR_=1 _N_=3

NOTE: 6 records were read from the infile "d:\sas\pumpkin2.txt".

The minimum record length was 52.

The maximum record length was 53.

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.

NOTE: The data set WORK.PUMPKIN2 has 5 observations and 7 variables.

NOTE: DATA statement used (Total process time):

real time 0.42 seconds

cpu time 0.04 seconds

I have attached the text file

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your input statement is requiring two spaces to end finding the name, but in the third row there is only one.

Your example data looks like you can just use column input instead of list mode input.  At least for the first 4 fields.

data want;

   infile cards truncover;

  input name $ 1-16 age 18-19 type $ 21 @ 23 date mmddyy10. score1-score5;

  format date date9.;

/*--+----0----+----0----+----0----+----0----+----0----+ */

cards;

Alicia Grossman  13 c 10-28-2003 7.8 6.5 7.2 8.0 7.9

Matthew Lee       9 D 10-30-2003 6.5 5.9 6.8 6.0 8.1

Elizabeth Garcia 10 C 10-29-2003 8.9 7.9 8.5 9.0 8.8

Lori Newcombe     6 D 10-30-2003 6.7 5.6 4.9 5.2 6.1

Jose Martinez     7 d 10-31-2003 8.9 9.5 10.0 9.7 9.0

Brian Williams   11 C 10-29-2003 7.8 8.4 8.5 7.9 8.0

run;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

"NOTE: SAS went to a new line when INPUT statement reached past the end of a line."

Did you try adding the TRUNCOVER option to your INFILE statement to prevent SAS from continuing onto the next line?

Aquarian27
Calcite | Level 5

Latest update after using Truncover::::::::

Program:

data pumpkin2;
infile "d:\sas\pumpkin2.txt" truncover;
input name & $16. age : 2. type : $1. date : mmddyy10. score1-score3 : 4.1;
run;

Output :

Still 3rd row data is missingimage.jpg

Tom
Super User Tom
Super User

Your input statement is requiring two spaces to end finding the name, but in the third row there is only one.

Your example data looks like you can just use column input instead of list mode input.  At least for the first 4 fields.

data want;

   infile cards truncover;

  input name $ 1-16 age 18-19 type $ 21 @ 23 date mmddyy10. score1-score5;

  format date date9.;

/*--+----0----+----0----+----0----+----0----+----0----+ */

cards;

Alicia Grossman  13 c 10-28-2003 7.8 6.5 7.2 8.0 7.9

Matthew Lee       9 D 10-30-2003 6.5 5.9 6.8 6.0 8.1

Elizabeth Garcia 10 C 10-29-2003 8.9 7.9 8.5 9.0 8.8

Lori Newcombe     6 D 10-30-2003 6.7 5.6 4.9 5.2 6.1

Jose Martinez     7 d 10-31-2003 8.9 9.5 10.0 9.7 9.0

Brian Williams   11 C 10-29-2003 7.8 8.4 8.5 7.9 8.0

run;

Linlin
Lapis Lazuli | Level 10

Borrowed Art's code:

data pumpkin2 ;
length name $ 16;
infile "c:\temp\forum\pumpkin2.txt"  ;
input @;
    _infile_=catx("  ",substr(_infile_,1,anydigit(_infile_)-1),
                substr(_infile_,anydigit(_infile_)));
input name & age : 2. type : $1. date : mmddyy10. (score1-score3) ( 4.1);
run;

proc print;run;

          Obs          name          age    type     date    score1    score2    score3

           1     Alicia Grossman      13     c      16006      7.8       6.5       7.2
           2     Matthew Lee           9     D      16008      6.5       5.9       6.8
           3     Elizabeth Garcia     10     C      16007      8.9       7.9       8.5
           4     Lori Newcombe         6     D      16008      6.7       5.6       4.9
           5     Jose Martinez         7     d      16009      8.9       9.5      10.0
           6     Brian Williams       11     C      16007      7.8       8.4       8.5

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1024 views
  • 4 likes
  • 3 in conversation