BookmarkSubscribeRSS Feed
spg
Obsidian | Level 7 spg
Obsidian | Level 7

Hi,

I used an infile statement to convert a data file into a SAS dataset in UNIX.

libname here '.';

data here.a1;

       infile "pos1" dsd dlm='|' firstobs=2 missover;

         input MKT $ STORE $  WEEK $ DATE $ USE $ ........

run;

I want to read in about 50 variables, but I get the following warning, and it also messes up a few columns.

WARNING: Truncated record.

Can somebody help? Also, is there a smarted way to read in all variables from the dataset?

Thanks!

15 REPLIES 15
art297
Opal | Level 21

You probably need to add an lrecl option to your infile statement and, with it, tell SAS the maximum length that your records will have.

ballardw
Super User

Are any of the string variables supposed to contain blank spaces? That will likely require some additional options as well.

art297
Opal | Level 21

Another suggestion: try proc import!  You can either look up the code or, from the SAS menu, click on file ->import.

I often use that method, and then click on F4 to retrieve the submitted code and, if necessary, modify it accordingly.

spg
Obsidian | Level 7 spg
Obsidian | Level 7

Thanks all.

I tried using the lrecl option, no luck. None of the variables are supposed to contain blank spaces either.

I do use the proc import a lot. In this case, I'm trying to convert a data file into a SAS file in UNIX, hence theinfile option.

ballardw
Super User

"Supposed to" and "Doesn't" are two entirely different things. Blanks or other non-printable characters such as tabs or carraige returns find there way into the data sometimes.

Another option to look at when reading files from other OS is BLKSIZE, it may be there is a logic, often 512 byte, structure to the file that Windows doesn't use.

Ksharp
Super User

Maybe you need to expand the length of variables.

(MKT  STORE   WEEK  DATE  USE) ( : $200.)

Ksharp

arnab61
Calcite | Level 5

If your string is containing blanks that will create a problem. So first look if there is any missing values are there or not. Though u have used missover but that will not help if any values are missing in between.

Use lrecl with some large value. Otherwise you can go for Proc import.

spg
Obsidian | Level 7 spg
Obsidian | Level 7

Ksharp: i used your clue. i don't get an error any more , but some of the column values are incorrect.

art297
Opal | Level 21

Did you add an lrecl option?  And, are all of your data for a specific records on separate lines?  If so, you may want to use truncover rather than missover.

Haikuo
Onyx | Level 15

Can you post some samples of those incorrectly input columns?

spg
Obsidian | Level 7 spg
Obsidian | Level 7

Well, here is the code I re-ran:

libname now '.';

data now.a1;

infilE "pos1" dsd dlm='|' firstobs=2 lrecl=4096 missover;

input (MKT STORE WEEK DATE USE ...50 VARIABLE) (: $200.);

run;

It gives me correct values for the first 10 columns or so and then messes up the others. E.g the price column returns a lot of 0s, whereas there are no 0-prices in my data.

Ksharp
Super User

As art said ,try to use 'truncover ' or   'missover pad'

The best way is to post some sample data, then we can check it more.

Ksharp

spg
Obsidian | Level 7 spg
Obsidian | Level 7

Thank you all for all the valuable inputs. I finally got my code to work. There was actually a column with missing values and once I accounted for that, the code ran fine.

Thanks again, all!

ballardw
Super User

0ne useful SAS utility you may have available is FSLIST. Type FSLIST on the command line and browse to the file of interest at the prompt OR if you have associated a FILENAME  then type FSLIST <Your filename reference>.

It will show lines of hte file as straigt text. It is NOT and editor, just a viewer. But it is handy to identify columns where things may be going odd and if there are different length lines. In the case of a pipe delimited file it would let you see whare multiple delimiters are adjacent indicating missing data. It is not the fastest tool but I find uses for it regularly as I deal with a variety of data file sources that are often not quite as advertised.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 15 replies
  • 5021 views
  • 0 likes
  • 7 in conversation