BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GeorgeSAS
Lapis Lazuli | Level 10
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! 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
Reeza
Super User

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;
Tom
Super User Tom
Super User

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;

 

GeorgeSAS
Lapis Lazuli | Level 10

Thank you all so much !

 

I also like the funny cartoon you shared with us.

ChrisBrooks
Ammonite | Level 13

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 880 views
  • 4 likes
  • 4 in conversation