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


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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
ballardw
Super User

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.

maroulator
Obsidian | Level 7

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;

BrunoMueller
SAS Super FREQ

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;

maroulator
Obsidian | Level 7

Thanks!

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
  • 613 views
  • 5 likes
  • 3 in conversation