BASE SAS Programming – Understanding SAS Formats

In the previous post we discussed the use of  SAS Informats. It is a useful method to read in the data files appropriately from a variety of formatted sources of raw data files. However, when opting for this method, we end up looking at the raw data in the tables as raw values. For instance, date fields read in by this method are displayed as numeric values and it is somewhat troublesome to understand the actual values as present originally in the raw data. This is where the  SAS formats come in. SAS formats enable us to format the imported data in a way where it would seem presentable and more easily readable.

Let us consider the SAS program as example:

data test;
input  @1 Name $5. @7 Balance 4.  @12 DOB mmddyy10.   @23 Gender $1.   ;
format DOB date9. Balance 4.2;

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

In the above SAS program, we are importing the date field ‘DOB’ using  SAS Informats. This field is now being read in as numeric information with respect to the SAS system date. When we apply the SAS format statement in the data step, we can change the way the numeric values are displayed. Check out the output table from this SAS program below:

SAS Program:

SAS Log:

Output Tab:

As it can be seen in the screenshot of the output tab, we are able to display the date values in a format, which is different from the SAS informat that was used to import from the raw data lines. See below the screenshot, where the dates have been formatted using the  SAS format mmddyy8.

Just SAS provides the flexibility to import raw data using a variety of SAS Informats, there are many options to format the data points as well. As you keep progressing further you will get familiar with the most commonly used  SAS Informats & Formats. It is important to practice on actual data sets to get familiar with these concepts as soon as possible. There are a significant number of questions in the BASE SAS certification examination from this topic.

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.