DATA Step, Macro, Functions and more

lose rows of data unexpectedly

Accepted Solution Solved
Reply
Super Contributor
Posts: 267
Accepted Solution

lose rows of data unexpectedly

data aa00;
input name $100.;
cards;
A20GE
ABSSVC
ADTPCLS
ADULTPED
AGEGP
APPTNO
AREANAME
BUCKET
BUSLIN
BUSLINE
BUSTYP
BUSTYPE
CLASSCD
CL_FAC
CL_MOB
CNTYNAME
CSANAME
DEDCT
DEP2CCIN
EDPFACID
;run;

if I change $100. to $45. it will be ok. can anyone explain the magic in it?

 

Thanks! 


Accepted Solutions
Solution
‎02-15-2018 01:55 PM
Super User
Super User
Posts: 7,860

Re: lose rows of data unexpectedly

Posted in reply to GeorgeSAS

https://condenaststore.com/featured/then-dont-do-that-robert-leighton.html

 

Since your lines are 80 characters or less when you try to read 100 characters from them SAS will go to the next line to find enough characters.

Either add an INFILE statement so that you can specify the TRUNCOVER option to prevent SAS from going to a new line,

 

data aa00;
  infile cards truncover ;
  input name $100.;
cards;

or since you seem to want to read the whole line you could just use the _INFILE_ buffer.

data aa00;
  length name $100 ;
  input;
  name = _infile_;
cards;

or don't use such a large informat. Note in-line data (CARDS/DATALINES) will have a LRECL that is a multiple of 80. 

data aa00;
  input name $80. ;
cards;

 

View solution in original post


All Replies
Super User
Posts: 22,873

Re: lose rows of data unexpectedly

Posted in reply to GeorgeSAS

Read the log. 

 

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.AA00 has 10 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
 
When you specify $100 inline (on the INPUT statement) like that SAS is trying to find 100 characters. If you're trying to specify the variable length, try using a LENGTH or INFORMAT instead.
 
data aa00;
informat name $100.;
input name;
Solution
‎02-15-2018 01:55 PM
Super User
Super User
Posts: 7,860

Re: lose rows of data unexpectedly

Posted in reply to GeorgeSAS

https://condenaststore.com/featured/then-dont-do-that-robert-leighton.html

 

Since your lines are 80 characters or less when you try to read 100 characters from them SAS will go to the next line to find enough characters.

Either add an INFILE statement so that you can specify the TRUNCOVER option to prevent SAS from going to a new line,

 

data aa00;
  infile cards truncover ;
  input name $100.;
cards;

or since you seem to want to read the whole line you could just use the _INFILE_ buffer.

data aa00;
  length name $100 ;
  input;
  name = _infile_;
cards;

or don't use such a large informat. Note in-line data (CARDS/DATALINES) will have a LRECL that is a multiple of 80. 

data aa00;
  input name $80. ;
cards;

 

Super Contributor
Posts: 267

Re: lose rows of data unexpectedly

[ Edited ]

Thank you all so much !

 

I also like the funny cartoon you shared with us.

Valued Guide
Posts: 561

Re: lose rows of data unexpectedly

Posted in reply to GeorgeSAS

In my opinion you should ALWAYS set an explicit length for your character variables. If you don't you could end up with the same variable on different files having different lengths which could lead to problems if you try to to append or merge them.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 132 views
  • 4 likes
  • 4 in conversation