Reading Column Data That Require Informats - SAS Programming

Instead of using starting and ending column numbers to describe the location of the data,you can use the starting column number,the length of the data value (number of columns it occupies),and a SAS informat.A typical data description containing information about the previouscollection of data might look like the following:

Reading Column Data That Require Informats

The following code uses pointers and informats to read instream data that occur in the pattern described above.


INPUT @1 ID 3.
65 GENDER $1.
67 AGE 2.
610 HEIGHT 2.
101 M 26 68 012366
102 M 32 78 031460
103 F 45 62 112647
104 F 22 66 080170
TITLE 'Example';

The @ characters (at signs) are called column pointers;they indicate the starting column for an action.When they appear before a variable name in an INPUT statement,they tell the SAS System to go to a certain column. Following the name of the variable, you can use an informat to tell the program how to read the data.

There are many types of SAS informats,but we only use a few common ones here.Numeric variables use an informat of the form w.d,where w is the width of the field (number of columns)containing the data,and d is the number of places to the right of the decimal point in the value. When d is omitted, it is assumed to be 0.If the data values actually contain decimal points,the d part of the specification is ignored.

A minus sign (-) may be included in a negative value,but it mustimmediately precede the value with no intervening space.The width,w,must be large enough to include any decimal points or minus signs found in the data. Character informats are of the form $w.,where w is the width of the field (number of columns)containing the data.

There are a large number of dale informats in the SAS System.The one used here, MMDDYY6.,instructs the software to read a data value from six columns, the first two being the month,the next two the day of the month,and the last two being the year. If the values contain special characters (typically slashes or dashes) separating the three parts of the dale, you can use MMDDYY8. instead.

All SAS informats contain a period (.), either as the last character in the formal or immediately preceding the number of decimal places contained in a data value.Omitting this period, like omitting the "sacred semicolon, "can,under the right circumstances,cause countless hours of head-scratching while trying to discover why the obtained results are so wrong!It is quite possible to omit a period or semicolon and still have "syntactically correct"code.Of course the results may be pure garbage.Two words to the wise are all that we can offer.BE CAREFUL!! Output from the previous code in Example 6 is as follows

Output from Example - Reading Column Data That Require Informats

Output from Example - Reading Column Data That Require Informats

Notice that the values for DOB are printed in MM/DD/YY formal.This is accomplished withthe line of code,FORMAT DOB MMDDYY8. (See the writeup accompanying Example 3.1 for an explanation).

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

SAS Programming Topics