BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
soumyatejas
Calcite | Level 5

Problem:

Mismatch in field picked from file while reading in data.

 

Code:

FILENAME trans6'/folders/myfolders/transaction_date.txt';

data trans6;
infile trans6;
input @1 trans_date mmddyy10.
@12 id $6.
;
run;

proc print data=work.trans6;
run;

 

Output:

output.JPG

 

Log:

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 FILENAME trans6'/folders/myfolders/transaction_date.txt';
57
58 data trans6;
59 infile trans6;
60 input @1 trans_date mmddyy10.
61 @12 id $6.
62 ;
63 run;
 
NOTE: The infile TRANS6 is:
Filename=/folders/myfolders/transaction_date.txt,
Owner Name=root,Group Name=vboxsf,
Access Permission=-rwxrwx---,
Last Modified=16Apr2017:14:32:11,
File Size (bytes)=50
 
NOTE: 3 records were read from the infile TRANS6.
The minimum record length was 12.
The maximum record length was 17.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.TRANS6 has 2 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
 
 
64
65 proc print data=work.trans6;
66 run;
 
NOTE: There were 2 observations read from the data set WORK.TRANS6.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
 
 
67
68
69 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
81
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Add the truncover option to your infile statement. e.g.:

 

FILENAME trans6 '/folders/myfolders/transaction_date.txt';

data trans6;
  infile trans6 truncover;
  input @1 trans_date mmddyy10.
  @12 id $6.;
run;

Art, CEO, AnalystFinder.com

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

Add the truncover option to your infile statement. e.g.:

 

FILENAME trans6 '/folders/myfolders/transaction_date.txt';

data trans6;
  infile trans6 truncover;
  input @1 trans_date mmddyy10.
  @12 id $6.;
run;

Art, CEO, AnalystFinder.com

soumyatejas
Calcite | Level 5
Thank you, it works fine now.
Cynthia_sas
SAS Super FREQ
Good catch, Art! I completely spaced out on TRUNCOVER.
cynthia
Cynthia_sas
SAS Super FREQ

Hi:

  When you read a file like this, SAS is telling you in the log, what is wrong with these lines:

The minimum record length was 12.
The maximum record length was 17.
 
And if you look at the file in Notepad,
what_is_in_file.png
you can see that indeed, the middle data line is only 12 bytes long. But with formatted input, such as you have used, when SAS gets to the second line and does not find the right number of bytes for ID (you told it $6), then you get the message: 
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
 
Because the INPUT statement went to the next line to "satisfy" the need to read $6, as you instructed. 
 
  There are other ways to read this data file. The easiest is to switch to LIST input, as shown below, but you can stick with formatted input if you use $varying to read ID. Other options, like PAD and/or MISSOVER can help you here. In total, there are 4 ways shown in my examples, There are probably more ways.
 
cynthia

 

simple_list_input_easiest.png

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1651 views
  • 4 likes
  • 3 in conversation