SAS Informat Statement

SAS Informat is an instruction that SAS used to read data values into a variable. Generally Informats are used to read or input data from external files specified in input statement. If coded with the informat statement, attach an informat to a variable for subsequent input.

  • Informats can be user-written informats also.

SAS Informat syntax :

INFORMAT variable-1<informat-1&gt; variable-N&gt;;

Informats categories

  1. Character Informats.
  2. Numeric Informats.
  3. Data, Time, Datetime Informats.
  4. Column binary Informats.
  5. User defined Informats.
ADVERTISEMENT

Character Informats

It Reads data into character variables.

  • Syntax:- $informatw.

Examples :-

  • $
  • $100
  • $30
  • $Char

Character Informats example program.

Data Informat01;
Infile datalines;
Input ID Name$ Age Sal;
Datalines;
001 David 29 40000
002 Amelia 40 50000
003 Gautham 29 54000
004 Arifa 30 25000
;
Run;
Proc print data=Informat01;
Run;

Numeric Informats

  • Numeric Informats reads numeric data values from numeric variables.

Syntax :- Comma2, Comma10.7

Numeric Informat example program.

Data Informat2;
Infile datalines;
input Idnumber Name$ age sex$ Sal comma6.;
Datalines;
0001 David 30 M 10,0000
0002 Virat 35 M 90,0000
0003 Diya 29 F 30,000
0004 Devilliers 38 M 60,000
0005 Ravi 40 M 75,000
Run;
Proc print data=informat2;
Run;

In the above program, we observe Sal variable is containing comma with values. Here Sal is numeric variable but comma is special character so we can’t read data. In this case, we can specify informat to read data,  not only with comma when numeric data contains comma, dollar we can specify numeric informats as shown above.

SAS Informat Example2:- 

Data Informat3;
Infile datalines;
input Idnumber Name$ age sex$ Sal dollar5.;
Datalines;
0001 David 30 M $10000
0002 Virat 35 M $90000
0003 Diya 29 F $3000
0004 Devilliers 38 M $6000
0005 Ravi 40 M $7500
Run;
Proc print data=informat3;
Run;

Data and time Informats:-

Data and time informats read data and time expression values into variables representing time, dates and date times. SAS converts all of these data into a single number. Dates after January 1, 1960, are positive integers and dates before January 1, 1960 are negative integers.

 Example :- 

DateSAS Internal Value
January 1, 19600
January 5, 19604
December 31, 1959-1
June 18, 200616,970

SAS Date Informat

The digit at the end of the SAS date Informat (mmddyy10), here 10 indicates the minimum width of the date string. To process any date input use anydtdte15.

  Input Date  Date Width  Informat
Date7.  7 29Jan10
Date9.  9 29Jan2010
Date11.  1129-Jan-2010
ddmmyy8.  8 29/01/10
ddmmyy10.  10 29/01/2010  29-01-2010
Anydate15.  15 29-Jan-2010
worddate20.  20 January 10, 2010

Some examples of common date and time formats :

  • DATEw.
  • DATETIMEw.
  • MMDDYYw.
  • TIMEw.

Date and time informats example program.

Data Informat4;
Infile datalines;
input Idnumber Name$ age sex$ Sal dob date9. doj:ddmmyy10.;
/*input Idnumber Name$ age sex$ Sal dob anydate9. doj:ddmmyy10.;*/
Datalines;
0001 David 30 M 10000 10Feb1983 12/02/2011
0002 Virat 35 M 90000 18Jun2006 15/01/2011
0003 Diya 29 F 3000 14Jun1988 31/01/2011
0004 Devilliers 38 M 6000 13Feb1980 25/02/2011
0005 Ravi 40 M 7500 10Aug1981 08/03.6.01
Run;
Proc print data=informat4;
Run;

Column Binary Informats

Column binary informats reads data stored in column-binary or multi-punched form into character and numeric variables.

Example:- row 12.3, $ cd4.

User defined SAS informats:-

User defined SAS informats are created by using proc format. In SAS programmer can create his own informats to read the data using Proc format.