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;
You have tabs in your datalines, so use those as delimiter. And remove the surplus input statement.
data idnew2;
infile cards dlm='09'x dsd;
length id $3 ikey 8 acode presence 8;
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
;
You have tabs in your datalines, so use those as delimiter. And remove the surplus input statement.
data idnew2;
infile cards dlm='09'x dsd;
length id $3 ikey 8 acode presence 8;
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
;
Either use
dlm='09'x
in your infile statement as you have tabs in your data and get rid of the extra input statement. or simply do this (with spaces)
data idnew2;
infile datalines;
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
;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.