BASE SAS Programming – Understanding SAS Informats




Up to this point, we have discussed the various scenarios to understand how to input data into SAS. In this post of the “BASE SAS Tutorial” series, we would take a more detailed look into how SAS implements the use of the Informats with the Input statement.

We would of course refer you to a book like ‘SAS by Example‘ by Ron Cody to get the formal understanding.  However, we will aim to provide a more workable understanding. Let us consider the datalines as listed below:


In these data lines, one way to read in all the fields is to simply import all of the fields as character values. However, informats allow us to store the values as they are intended. For instance, if we store the date values in these data lines as a character data type, it would be unavailable to leverage any date specific calculations that we may wish to perform. We would end up converting it to a numeric/date format and then applying the desired functions.

Let us consider the outputs from both approaches i.e., importing the date field as a character and using informats.

SAS Program/Output when Imported as character:

data test2;
input  @1 Name $5. @7 Balance 4.  @12 DOB $10.   @23 Gender $1.   ;

datalines;
Jimmy 45.5 12/11/1999 M
Julie 23.2 1/14/2011  F
Tom   20    1/1/2001  M
;
run;

Output/Log:

SAS Program/Output when Imported with Informats:

data test1;
input  @1 Name $5. @7 Balance 4.  @12 mmddyy10.  @23 Gender $1.   ;

datalines;
Jimmy 45.5 12/11/1999 M
Julie 23.2 1/14/2011  F
Tom   20    1/1/2001  M
;
run;

As it can be seen in the above outputs from the two SAS programs, the SAS informats enable allow the storage of the values based on the formats present in the raw formats. However, it is worth noting that although SAS informats  allow for data points to be stored correctly, it is rather inconvenient to view them as the numeric values. It is not always clear as to what the actual date values are. These are addressed by the SAS format statements. These will be discussed in later posts. Keep in mind, SAS Informats  are available for many standard layouts for dates and numeric values (to address decimals, currencies etc.). For instance, amounts may have currency formats or the comma formats depending the region where the data is extracted. SAS Informats are very useful to capture such layouts accurately.

We certainly hope, this was useful in clarifying the understanding. Some of the most tricky questions in the BASE SAS certification are picked from this topic. We recommend, please keep practicing and working hard.

You can 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.