BASE SAS Programming – Fixed Column Input




Previously we discussed how to import data using the list input method. In this post  in the ‘BASE SAS tutorial” series, we would be discussing how to import data using the fixed columns method. There are two approaches within the fixed column method. The first is the Column Input. Under this approach, we provide the range of the fields as present in the raw data. Consider the below SAS program as an example.

data test;
input Subj        $ 1-3
DOB       $ 4-13
Gender  $ 14
Balance  15-21;

datalines;
00110/21/1955M 1145
00211/18/2001F 18722
00305/07/1944M 123.45
00407/25/1945F -12345
;
run;

We can the see the datalines are formatted such that all individual fields are within fixed lenghts without any overlap. In such cases, the input can written as in the SAS program above, where the range of the fields is specified along with the indication of whether or not the field is a character value. So in our example, we can see that the field DOB is being read as a character field ranging from the 4 character (from the left) to a width of 9 characters up to the 13th. All remaining fields are also defined in a similar fashion.

See below for the resulting logs and outputs from the above SAS program in the SAS University Edition interface:

LOG:

Output Tab:

 

It should be noted, that the raw data may not always be present in fixed width columns without overlap. These cases may be quite rare and may only be applicable to smaller projects. It is an important concept, nonetheless. It shows of the versatility of the Input Statement.

Please find relevant reference books in the sidebar of this post, if you should want to purchase the same for further studying. BASE SAS Certification guide and the Little SAS book are extremely useful for preparation and also act as a wonderful reference for SAS concepts.

Please sign up for our newsletter, so that we may keep you posted on the latest activity on our website and Youtube channel.