SAS Programming

DATA Step, Macro, Functions and more
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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 4073 views
  • 2 likes
  • 2 in conversation