3
votes

I'm using Sas studio university edition. I have a dat file without any column headings (4 columns). I'm trying to read it in with

data van;
    infile "/folders/myfolders/test2/psek-win.dat";
    input a $ b $ c $ d $;
run;

i.e. create my own names for the columns. It works, but only the very first line is being read in. How can I get it to read all lines? I have been watching youtube tutorials but I'm stuck.

EDIT: Here is the output

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 57         
 58         data van;
 59             infile "/folders/myfolders/test2/psek-win.dat";
 60             input a $ b $ c $ d $;
 61         run;

 NOTE: The infile "/folders/myfolders/test2/psek-win.dat" is:
       Filename=/folders/myfolders/test2/psek-win.dat,
       Owner Name=sasdemo,Group Name=sas,
       Access Permission=-rw-rw-r--,
       Last Modified=05Jun2015:06:55:44,
       File Size (bytes)=1527

 NOTE: 1 record was read from the infile "/folders/myfolders/test2/psek-win.dat".
       The minimum record length was 1527.
       The maximum record length was 1527.
 NOTE: The data set WORK.VAN has 1 observations and 4 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.01 seconds
       cpu time            0.01 seconds


 62         
 63         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 75      

EDIT 2: I really should have included this info from the start...sorry: I'm using Windows 7, running Sas Studio through VirtualBox on Linux Redhat 64. I realized the file I was using was meant for Windows. When I use a Linux version of the same file it works fine.

Thanks

2
What do you see in the log?DWal
Are you sure this is SAS dataset? For window OS, after SAS8, SAS data file is .sas7bdat, and if is is SAS data, you could read directly not need infile and input.Shenglin Chen
Added the output, will try the solutions proposed below when I get home. Thanks!L Xandor
@LXandor Just to be clear, is 1527 the expected line width for this file, or are you expecting something much shorter? And can you update with your OS? And when you open the file in notepad/etc., do you see multiple lines - or do you have a different reason to believe the lines are there?Joe

2 Answers

3
votes

Most of the time, if SAS is only reading one line and then acting as if it were done when it has many lines, it is a problem with the line terminator (ie, the end-of-line character(s)).

Windows uses CR+LF (0D0A) while Unix/Linux use 0A (LF), including Mac OS X.

This means that if you're on a Windows machine and have a Unix terminated file, it will be read in as if it has only one line. The other way around usually isn't a problem - you get an extra character that might make a bit of a mess, but it still acts as if it were the right number of lines.

You can alter this in the datastep by specifying the termstr= option to specify the correct line terminator. So for example:

data van;
    infile "/folders/myfolders/test2/psek-win.dat" termstr=lf;
    input a $ b $ c $ d $;
run;

Would instruct SAS to consider a simple line feed to be a line terminator.

0
votes

I realized the file I was using was meant for Windows. When I use a Linux version of the same file it works fine. Thanks for the help