BookmarkSubscribeRSS Feed
ak2011
Fluorite | Level 6
I would appreciate if someone could help me with the SAS code to properly read the dataset below:
I have missing values and SAS log produced an error message.There were 21 obs but SAS read only 17.
Please help. Thanks. The SAS log is shown below.


data idnew1m;
input id$ job idchem;
datalines;
os1 1 990005
os1 1 990021
1 210701
os1 1 211700
os1 2 211700
os1 2 990021
os2 2
os1 2 210701
os1 2 990005
os2 1 210701
os2 211700
os2 1 990005
os2 2 990021
os2 3 210701
os2 3 990005
os3 3 210701
os3 1 211700
os4 1 210701
os4 1 990005
os4 1 211700
os5 990021
;
run;

proc print data=idnew1m;
run;

.


1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data idnew1m;
74 input id$ job idchem;
75 datalines;
 
NOTE: Invalid data for idchem in line 79 1-3.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
79 os1 1 211700
id=1 job=210701 idchem=. _ERROR_=1 _N_=3
NOTE: Invalid data for idchem in line 83 1-3.
83 os1 2 210701
id=os2 job=2 idchem=. _ERROR_=1 _N_=6
NOTE: Invalid data for idchem in line 87 1-3.
87 os2 1 990005
id=os2 job=211700 idchem=. _ERROR_=1 _N_=9
NOTE: LOST CARD.
97 ;
id=os5 job=990021 idchem=. _ERROR_=1 _N_=18
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.IDNEW1M has 17 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
 
 
97 ;
98 run;
99
100 proc print data=idnew1m;
101 run;
 
NOTE: There were 17 observations read from the data set WORK.IDNEW1M.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.25 seconds
cpu time 0.25 seconds
 
 
102
103
104 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
116
 

 Thanks in advance.

ak.

2 REPLIES 2
Tom
Super User Tom
Super User

If you want to use list mode input, like in your INPUT statement, then you need to have a value for every field. Use a period to indicate missing values (for both numeric and character variables).

data idnew1m;
  input id$  job idchem;
datalines;
os1 1 990021
.   1 210701
os2 2 .
os2 . 211700 
os4 1 211700
;

Or make sure the values are always in the same place on the line.  Then you could switch to formattted input 

data idnew1m;
  input id $3. +1 job 1. +1 idchem 5.;
datalines;
os1 1 990021
    1 210701
os2 2
os2   211700
os4 1 211700
;

or column based input.

data idnew1m;
  input id $ 1-3 job 5 idchem 7-12 ;
datalines;
os1 1 990021
    1 210701
os2 2
os2   211700
os4 1 211700
;

You could still use list mode if you used to the DSD option to interpret adjacent delimiters as representing a missing value.  Normally you would use something other than space as the delimiter in that case.

data idnew1m;
  infile datalines dsd dlm='|' truncover;
  input id$  job idchem;
datalines;
os1|1|990021
|1|210701
os2|2|
os2||211700 
os4|1|211700
;
ak2011
Fluorite | Level 6
Thanks very much, Tom! SAS reads perfect now!

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 277 views
  • 0 likes
  • 2 in conversation