Monday, October 18, 2010

The PAD option

When you read variable-length records that contain fixed-field data into a SAS data set, there might be values that are shorter than others or that are missing. The PAD option pads each record with blanks so that all data lines have the same length.

data new4;
    infile 'c:\myrawdata\infileoptions.txt' pad;
    input id $3.;
run;

We will get the following dataset:

Obs    id
   1     1
   2     22
   3     333
   4     444
   5     555

Sunday, October 17, 2010

Difference between infile option MISSOVER and TRUNCOVER

Both will assign missing values to variables if the data line ends before the variable’s field starts. But when the data line ends in the middle of a variable field, TRUNCOVER will take as much as is there, whereas MISSOVER will assign the variable a missing value.

For example, here is the raw data infileoptions.txt stored in c:\myrawdata\
1
22
333
4444
55555

With option MISSOVER:

data new1;
    infile 'c:\myrawdata\infileoptions.txt' misscover;
    input id $3.;
run;

We will get the following dataset:

Obs    id
   1
   2
   3     333
   4     444
   5     555

With optionTRUNCOVER:

data new2;
   infile 'c:\myrawdata\infileoptions.txt' truncover;
   input id $3.;
run;

We will get the following dataset:

Obs    id
   1     1
   2     22
   3     333
   4     444
   5     555

Without options:

data new3;
   infile 'c:\myrawdata\infileoptions.txt';
   input id $3.;
run;

We will get the following dataset that may not be what you expect:

Obs    id
   1     22
   2     333
   3     444
   4     555
                                                 

Wednesday, October 13, 2010

A way to automatically clear the log and the output windows

Each time that the SAS code is executed, the new log is appended to the previous logs and so does the output. The log and output windows can be manually cleared. The easy way is to use the DM statement to clear them automatically each time the SAS code is executed:

dm 'log; clear; out; clear;';