BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

Hi everyone,

I am trying to read a txt file into SAS using the infile statement.

The data look like this:

Var1      Var2          Var3

"John" , "Smith",      4.3

"Bob",    "Jones" ,    5.2

"Sarah",  "Johnson"  ,  .

I am using the following code:

data newdata;

infile 'filelocation.txt' dsd missover;

input var1 $ var2 $ var3;

run;

The problem is that I am getting error messages for instances where Var3 is missing (missing values are noted with a period).


Any help is much appreciated.

Thanks!

5 REPLIES 5
data_null__
Jade | Level 19

what is the error?

Walternate
Obsidian | Level 7

Invalid data for Var3 in line 123

data_null__
Jade | Level 19

Did SAS show the the line as in this example.

19         filename FT15F001 temp;
20         data newdata;
21            *infile 'filelocation.txt' dsd missover;
22            infile FT15F001 dsd missover;
23            input var1 $ var2 $ var3;
24            parmcards;
28         ;;;;

NOTE:
The infile FT15F001 is:
      (system-specific pathname),
      (system-specific file attributes)

NOTE: Invalid data for var3 in line
3 23-25.
RULE:     ----+----
1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                     
3         "Sarah""Johnson"  ,  x 25
var1=Sarah var2=Johnson var3=
. _ERROR_=1 _N_=3
NOTE:
3 records were read from the infile (system-specific pathname).
      The minimum record length was
25.
      The maximum record length was
26.
NOTE: The data set WORK.NEWDATA has
3 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time          
0.00 seconds
      cpu time           
0.02 seconds
     
data_null__
Jade | Level 19

So you have all the information you need.  You have the invalid data message and the offending record.  Case closed.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4350 views
  • 2 likes
  • 2 in conversation