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-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
  • 1121 views
  • 4 likes
  • 3 in conversation