Infile/Input Statements

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Infile/Input Statements


To whom it may concern,

I have been using the code below to read the data into SAS from the attached file.

I have observed the following two problems, which I think can be solved with the same solution.

1) My code doesn't seem to load values beyond month30.

2) My code loads a blank value for month18 and then loads incorrect values, which do not correspond to the ones in the attached file.

I know that the solution is simple, however, I can't seem to crack it.

Any help would be extremely appreciated.

data test;

  infile '/file location/.txt' dlm='090D'x;

  input location :$2 month1-month120;

run;

Attachment

Accepted Solutions
Solution
‎06-10-2014 04:08 PM
Super User
Posts: 10,516

Re: Infile/Input Statements

By current default with an infile statement the expected maximum data line lenght is 255 characters. I think your lines are exceeding that and not reading correctly. Add a LRecL=1500 (or a number at least as large as the number of characters) to the infile statement.

View solution in original post


All Replies
Solution
‎06-10-2014 04:08 PM
Super User
Posts: 10,516

Re: Infile/Input Statements

By current default with an infile statement the expected maximum data line lenght is 255 characters. I think your lines are exceeding that and not reading correctly. Add a LRecL=1500 (or a number at least as large as the number of characters) to the infile statement.

Frequent Contributor
Posts: 121

Re: Infile/Input Statements

ballardw,

Many thanks, this is extemely helpful; one more (minor problem) that arose, however, is this. Although your solution remedied both my problems, I find that the full length of my number isn't being accommodated; for example, I am missing the last 2 decimal digits for each one of my observations (the number I get in the data set is a rounded one) and my Informat doesn't seem to be helping, in addition to returning a blank for my last observation. Below is my new code.

Any thoughts?

data test;

  infile '/fmac/users/f371032/HPI.txt' dlm='090D'x LRecL=10000;

  input location $2. month1-month120 2.30;

run;

SAS Super FREQ
Posts: 683

Re: Infile/Input Statements

I guess it has to do with the format that is used by default BEST12. for displaying a number.

Add a FORMAT statement to your code like this:

data test;

  infile '/folders/myfolders/example.txt' dlm='090D'x LRecL=10000;

  input

   location : $2.

   month1-month120 : 8.

  ;

  format

    month1-month120 32.12

  ;

   

run;

Frequent Contributor
Posts: 121

Re: Infile/Input Statements

Thanks!

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 238 views
  • 5 likes
  • 3 in conversation