How to Use CNTLOUT= and CNTLIN=options In SAS PROC FORMAT?

Formats are used to display variable values or written as output in SAS using the PROC FORMAT statement.

The CNTLOUT= and CNTLIN=(options) are often used with the PROC FORMAT procedure in SAS when dealing with the user-defined formats.

PROC FORMAT Syntax

PROC FORMAT options; 	
    VALUE format_name specifications; 	
    INVALUE informat_name specifications; 	
    PICTURE format_name specifications; 
RUN;

You can categories SAS format into three parts. I’d rather call them methods.

Every method explained here can be used independently, depending on your requirements you can choose either of these.

  • Create User Defined Formats using VALUE statement
  • Create User Defined Formats using PICTURE format
  • Create User Defined Formats from DATA

1. Use PROC FORMAT with CNTLOUT= to Create SAS Data Set

You can export entire SAS format catalogues into a SAS work data set or permanent data set. It can be achieved through the proc format procedure with cntlout= option.

In this article we have already seen multiple examples on how to create temporary & permanent formats in SAS under ST00 library. We can use the same here to export those format data into sas data set.

The following code exports the entire SAS format catalogues into a SAS WORK data set called work.all_st00_formats.

/* libname statement */
libname ST00 '/home/u61950255/Production/Staging Tables';

/* export entire format catalogs */
proc format library=ST00 cntlout=work.all_st00_formats;
run;

/* view data */
proc print data=work.all_st00_formats;
run;
proc format cntlout output
work.all_st00_formats

The final output you may store in the permanent data set if required. Otherwise the work data set is more than enough to view format data and do analysis.

2. Use PROC FORMAT with CNTLIN= to Create Format Using SAS Data set

As demonstrated here (with examples) how to create format in SAS using proc format procedure with VALUE statement and PICTURE FORMAT statement.

It works fine with the small amount of data in the format. But it’s challenging when you’re dealing with slightly more data and want to create SAS format.

The CNTLIN=option in the proc format procedure is a life saver. You can create a format in one go using this option. The only prerequisite here is to create a data set with values to be used for format or use relevant existing data set.

For now I don’t have an existing data set hence let me create one for cars engine size group. We’ll use the sashelp.cars data set to apply this format. 

The format we’ll create is to group engine size and label it as small, medium, big size depending on the range we set.

The following criteria has been defined for the engine size:

EnginSize (1.0 to 2.0) ⇾  Small 
EnginSize (2.1 to 4.5) ⇾  Medium
EnginSize (4.6 to 8.0) ⇾  Large 
EnginSize (8.1 to 10 ) ⇾  XLarge++

You either have an existing data set where you have this information or you need to create a new data set with these values.

REMEMBER: Data set should be in the standard structure in order to use to create SAS format.

Data set Structure:
It should have the following variables: → fmtname, start, end, label, and type.

The following code creates the a new data set called work.EnginSizeGrp_CTRL which is to be used to create user-defined format EnginSizeGrp using proc format with CNTLIN=option

/* create a new data set*/
data work.EnginSizeGrp_CTRL;
	length fmtname $15;
	input fmtname $ start end label $ type $;
	datalines;
EnginSizeGrp 1 2 Small N
EnginSizeGrp 2.1 4.5 Medium N
EnginSizeGrp 4.6 8 Large N
EnginSizeGrp 8.1 10 XLarge++ N
;
run;
proc print;
proc format CNTLOUT CNTLIN option

Now use this data set work.EnginSizeGrp_CTRL to create a format EnginSizeGrp and store it in the SAS format catalog under library ST00.

The CNTLIN= option specifies that the data set EnginSizeGrp_CTRL is the source for the format EnginSizeGrp.

/* libname statement */
libname ST00 '/home/u61950255/Production/Staging Tables';

/* Insert values for a new format */
proc format library=ST00 cntlin=work.EnginSizeGrp_CTRL; 
run;
create format using sas data set

Now you can use the CNTLOUT=option to export the format data values to cross verify if you have successfully created a format using a data set with CNTLOUT=option.

The work.all_st00_formats should have entries for EnginSizeGrp along with other existing formats.

/* libname statement */
libname ST00 '/home/u61950255/Production/Staging Tables';


/* export entire format catalogs */
proc format library=ST00 cntlout=work.all_st00_formats;
run;
proc print;
CNTLOUT and CNTLIN options in proc format