BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ak2011
Fluorite | Level 6
Hi,
Could someone help me solve this problem:
I would like SAS to read the dataset below but I got an error message(posted below): Invalid
data check;
infile cards truncover;
input id ikey acode;
cards;
os1 1 990005
os1 1 9900021
os1 1 211700
os1 2 211700
os1 2 9900021
os1 2 210701
os1 2 990005
os2 2 9900021
os2 1 210701
os2 1 990005
os2 2 9900021
os2 3 210701
os2 3 990005
os3 3 210701
os3 1 211700
os4 1 210701
os4 1 990005
os4 1 211700
;

NOTE: Invalid data for id in line 77 1-3.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
77 os1 1 990005
id=. ikey=1 acode=990005 _ERROR_=1 _N_=1
NOTE: Invalid data for id in line 78 1-3.
78 os1 1 9900021
id=. ikey=1 acode=9900021 _ERROR_=1 _N_=2
NOTE: Invalid data for id in line 79 1-3.
79 os1 1 211700
id=. ikey=1 acode=211700 _ERROR_=1 _N_=3
NOTE: Invalid data for id in line 80 1-3.
80 os1 2 211700
id=. ikey=2 acode=211700 _ERROR_=1 _N_=4
NOTE: Invalid data for id in line 81 1-3.
81 os1 2 9900021
id=. ikey=2 acode=9900021 _ERROR_=1 _N_=5
NOTE: Invalid data for id in line 82 1-3.
82 os1 2 210701
id=. ikey=2 acode=210701 _ERROR_=1 _N_=6
NOTE: Invalid data for id in line 83 1-3.
83 os1 2 990005
id=. ikey=2 acode=990005 _ERROR_=1 _N_=7
NOTE: Invalid data for id in line 84 1-3.
84 os2 2 9900021
id=. ikey=2 acode=9900021 _ERROR_=1 _N_=8
NOTE: Invalid data for id in line 85 1-3.
85 os2 1 210701
id=. ikey=1 acode=210701 _ERROR_=1 _N_=9
NOTE: Invalid data for id in line 86 1-3.
86 os2 1 990005
id=. ikey=1 acode=990005 _ERROR_=1 _N_=10
NOTE: Invalid data for id in line 87 1-3.
87 os2 2 9900021
id=. ikey=2 acode=9900021 _ERROR_=1 _N_=11
NOTE: Invalid data for id in line 88 1-3.
88 os2 3 210701
id=. ikey=3 acode=210701 _ERROR_=1 _N_=12
NOTE: Invalid data for id in line 89 1-3.
89 os2 3 990005
id=. ikey=3 acode=990005 _ERROR_=1 _N_=13
NOTE: Invalid data for id in line 90 1-3.
90 os3 3 210701
id=. ikey=3 acode=210701 _ERROR_=1 _N_=14
NOTE: Invalid data for id in line 91 1-3.
91 os3 1 211700
id=. ikey=1 acode=211700 _ERROR_=1 _N_=15
NOTE: Invalid data for id in line 92 1-3.
92 os4 1 210701
id=. ikey=1 acode=210701 _ERROR_=1 _N_=16
NOTE: Invalid data for id in line 93 1-3.
93 os4 1 990005
id=. ikey=1 acode=990005 _ERROR_=1 _N_=17
NOTE: Invalid data for id in line 94 1-3.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
94 os4 1 211700
id=. ikey=1 acode=211700 _ERROR_=1 _N_=18

Thanks in advance
ak.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Your ID variable is alphanumeric and so can only be read as a character, which means you would need to indicate(tell sas) to read a char with a $ sign following the variable name. So, correct your input statement to

 

input id $ ikey acode;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Your ID variable is alphanumeric and so can only be read as a character, which means you would need to indicate(tell sas) to read a char with a $ sign following the variable name. So, correct your input statement to

 

input id $ ikey acode;
r_behata
Barite | Level 11

Review your input statement. Id needs to be read as a character.

 

 

input id $ ikey acode;

 

ak2011
Fluorite | Level 6
Hi,
I would greatly appreciate if someone help me resolve this problem. I had an invalid data reading message in SAS. I tried several reading options but I still had errors.
The code and log are found below. May I know the correct statement to use?
Thanks in advance.



data idnew2;
infile cards;
length id $3 ikey 8 acode presence 8;
input id$ 1-8 ikey acode presence;
input id$ ikey acode presence;
datalines;
os1 1 990005 1
os1 1 9900021 0
os1 1 211700 0
os1 2 211700 0
os1 2 9900021 0
os1 2 210701 0
os1 2 990005 1
os2 1 210701 0
os2 1 990005 1
os2 2 9900021 0
os2 3 210701 0
os2 3 990005 1
os3 1 211700 0
os3 3 210701 0
os4 1 210701 0
os4 1 990005 1
os4 1 211700 0
;
run;
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data idnew2;
74 input id$ ikey acode presence;
75 datalines;
 
NOTE: Invalid data for ikey in line 77 1-15.
NOTE: Invalid data for acode in line 78 1-14.
NOTE: Invalid data for presence in line 79 1-14.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
 
79 CHAR os1.2.211700.0
ZONE 67303033333303222222222222222222222222222222222222222222222222222222222222222222
NUMR F3192921170090000000000000000000000000000000000000000000000000000000000000000000
NOTE: Invalid data errors for file CARDS occurred outside the printed range.
NOTE: Increase available buffer lines with the INFILE n= option.
id=os1199 ikey=. acode=. presence=. _ERROR_=1 _N_=1
NOTE: Invalid data for ikey in line 81 1-14.
NOTE: Invalid data for acode in line 82 1-14.
NOTE: Invalid data for presence in line 83 1-14.
 
83 CHAR os2.1.210701.0
ZONE 67303033333303222222222222222222222222222222222222222222222222222222222222222222
NUMR F3291921070190000000000000000000000000000000000000000000000000000000000000000000
NOTE: Invalid data errors for file CARDS occurred outside the printed range.
NOTE: Increase available buffer lines with the INFILE n= option.
id=os1299 ikey=. acode=. presence=. _ERROR_=1 _N_=2
NOTE: Invalid data for ikey in line 85 1-15.
NOTE: Invalid data for acode in line 86 1-14.
NOTE: Invalid data for presence in line 87 1-14.
 
87 CHAR os2.3.990005.1
ZONE 67303033333303222222222222222222222222222222222222222222222222222222222222222222
NUMR F3293999000591000000000000000000000000000000000000000000000000000000000000000000
NOTE: Invalid data errors for file CARDS occurred outside the printed range.
NOTE: Increase available buffer lines with the INFILE n= option.
id=os2199 ikey=. acode=. presence=. _ERROR_=1 _N_=3
NOTE: Invalid data for ikey in line 89 1-14.
NOTE: Invalid data for acode in line 90 1-14.
NOTE: Invalid data for presence in line 91 1-14.
 
91 CHAR os4.1.990005.1
ZONE 67303033333303222222222222222222222222222222222222222222222222222222222222222222
NUMR F3491999000591000000000000000000000000000000000000000000000000000000000000000000
NOTE: Invalid data errors for file CARDS occurred outside the printed range.
NOTE: Increase available buffer lines with the INFILE n= option.
id=os3121 ikey=. acode=. presence=. _ERROR_=1 _N_=4
NOTE: LOST CARD.
93 ;
id=os4121 ikey=. acode=. presence=. _ERROR_=1 _N_=5
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.IDNEW2 has 4 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
 
 
93 ;
94 run;
95
96
97 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
109
 


 

ballardw
Super User

Your ID value contains values that are not numeric. You need to tell SAS the variable is to be read as character or it assumes numeric.

 

input id $ ikey acode;

The $ after the variable tells SAS to expect a character value of up to 8 characters in length.

If you need to read longer values you will need to either provide information prior to the input statement as to the length of the variable or specify and informat on the input statement to read longer values such as

input id $12. ikey acode;

Note the . after the 12 that helps SAS know that you mean an informat in this case.

ak2011
Fluorite | Level 6

Thanks very much. It works now!

ak.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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