BookmarkSubscribeRSS Feed
satishih77
Calcite | Level 5
PROC IMPORT DATAFILE= '/home/u44418748/MSc Biostatistics with SAS/Datasets/school.txt' 
OUT= outdata 
DBMS=dlm 
REPLACE; 
delimiter='09'x;
GETNAMES=YES; 
RUN;

I used the above code to import txt file in sas

But i got SAS log as 

NOTE: Invalid data for class_size in line 454 17-18.

454 CHAR 453.34.11.31.15.NA.23.125.12.188 32
ZONE 33303303303303304403323330332333
NUMR 4539349119319159E1923E125912E188
sl_no=453 school=34 iq=11 test=31 ses=15 class_size=. meanses=23.125 meaniq=12.188 _ERROR_=1 _N_=453
 
because class size is .  this is just one part of log
i have many missing value as . 
how can i import data sucessfully
2 REPLIES 2
Kurt_Bremser
Super User

First of all, the import seems to have worked, but it is a very good idea to get rid of all those pesky NOTEs that contain the string ERROR.

Your import did work because the NOTEs are caused by strings NA where you expect a number, and we can quite safely infer that NA should result in a missing number.

I recommend to use a dedicated informat:

proc format;
invalue na
  'NA' = .
  other = [best.]
;
run;

This custom informat reacts specifically to the string NA, and uses the default informat BEST for anything else.

And then write the data step yourself:

data want;
infile "yourfile" dlm='09'x dsd truncover firstobs=2;
input
  sl_no
  school
  iq
  test
  ses
  class_size :na.
  meanses
  meaniq
;
run;

As you can see, the data step is not complicated at all. For delimited text files, PROC IMPORT is not needed, you can write the step directly from the file documentation, and it will give you consistent results. If IMPORT had checked the file a little more, your column class_size would have ended up as character, something you would not want.

Ksharp
Super User
Add an option :

guessingrows=max ;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 559 views
  • 0 likes
  • 3 in conversation