DATA Step, Macro, Functions and more

Reading data from file - issue

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Reading data from file - issue

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

Accepted Solutions
Solution
‎04-16-2017 03:30 PM
PROC Star
Posts: 7,468

Re: Reading data from file - issue

Posted in reply to soumyatejas

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


All Replies
Solution
‎04-16-2017 03:30 PM
PROC Star
Posts: 7,468

Re: Reading data from file - issue

Posted in reply to soumyatejas

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

New Contributor
Posts: 2

Re: Reading data from file - issue

Thank you, it works fine now.
SAS Super FREQ
Posts: 8,864

Re: Reading data from file - issue

Good catch, Art! I completely spaced out on TRUNCOVER.
cynthia
SAS Super FREQ
Posts: 8,864

Re: Reading data from file - issue

Posted in reply to soumyatejas

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

 

☑ This topic is solved.

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

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