03-06-2012 03:25 PM
I used an infile statement to convert a data file into a SAS dataset in UNIX.
libname here '.';
infile "pos1" dsd dlm='|' firstobs=2 missover;
input MKT $ STORE $ WEEK $ DATE $ USE $ ........
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?
03-06-2012 06:28 PM
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.
03-06-2012 10:48 PM
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.
03-07-2012 11:11 AM
"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.
03-07-2012 12:53 AM
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.
03-07-2012 10:46 AM
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.
03-07-2012 01:18 PM
Well, here is the code I re-ran:
libname now '.';
infilE "pos1" dsd dlm='|' firstobs=2 lrecl=4096 missover;
input (MKT STORE WEEK DATE USE ...50 VARIABLE) (: $200.);
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.
03-10-2012 11:16 PM
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!
03-12-2012 10:35 AM
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.