Help using Base SAS procedures

INFILE statement not reading all variables

Reply
Contributor spg
Contributor
Posts: 61

INFILE statement not reading all variables

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!

PROC Star
Posts: 7,468

INFILE statement not reading all variables

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.

Super User
Posts: 11,343

INFILE statement not reading all variables

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

PROC Star
Posts: 7,468

INFILE statement not reading all variables

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.

Contributor spg
Contributor
Posts: 61

INFILE statement not reading all variables

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.

Super User
Posts: 11,343

INFILE statement not reading all variables

"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.

Super User
Posts: 10,020

INFILE statement not reading all variables

Maybe you need to expand the length of variables.

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

Ksharp

Occasional Contributor
Posts: 15

INFILE statement not reading all variables

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.

Contributor spg
Contributor
Posts: 61

INFILE statement not reading all variables

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

PROC Star
Posts: 7,468

INFILE statement not reading all variables

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.

Respected Advisor
Posts: 3,156

INFILE statement not reading all variables

Can you post some samples of those incorrectly input columns?

Contributor spg
Contributor
Posts: 61

INFILE statement not reading all variables

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.

Super User
Posts: 10,020

INFILE statement not reading all variables

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

Contributor spg
Contributor
Posts: 61

INFILE statement not reading all variables

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!

Super User
Posts: 11,343

INFILE statement not reading all variables

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.

Ask a Question
Discussion stats
  • 15 replies
  • 1758 views
  • 0 likes
  • 7 in conversation