Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
Variable Attributes [17-17]


Attribute #6: Informat
Picture

Variable Informat identifies the form of data in SAS.

It is mostly used when (1) reading in an external file, or (2) converting a character variable into a numeric variable.

In this session, we will focus on the latter. 
Picture

In the CHAR data set, there are 3 variables:
  • Date
  • Time 
  • Amount

All 3 variables are character variables. 
Picture

Having the date, time and amount data in character variables is not recommended, as no calculation can be done on the "text".


INPUT function

As opposed to the PUT function, the INPUT function converts the variable from character back to numeric.

Let's take a look at the following example.

Example

Data Char2;
Set Char;
Date2 = Input(Date, yymmdd10.);
Run;
Picture

The INPUT function creates a new variable called Date2, which contains the numeric form of the date from the original Date variable. 

E.g. 2015-01-01 --> 20089

Date2 is a numeric variable:
Picture

Structure of INPUT function

Similar to the PUT function, the INPUT function takes on two parameters:
  1. The character variable to be converted.
  2. The informat to use for conversion
Picture

In this example, the informat used is (YYMMDD10.).
Picture

Selecting the Informat

When using the Input function, you must select an informat that matches the form of the original data.

In our example, the data from the Date variable has the form of YYYY-MM-DD:
Picture

E.g. 2015-01-01

This matches the informat of (YYMMDD10.). 

As a result, the (YYMMDD10.) is used in the Input function.

Let's take a look at another example.

Example

Data Char3;
Set Char;
Time2 = Input(Time, Time8.);
Run;
Picture

In this example, the data from the Time variable has the form of (HH:MM:SS).

E.g. 8:00:00


This is matched by the informat of (time8.).  

Using the informat of (time8.) successfully converts the Time variable from character back to its numeric time representation:

E.g. 8:00:00 --> 28800

Exercise
The Amount variable from the CHAR data set above has yet to be converted into numeric.

Convert the variable into numeric using the Input function. 
Next

Need some help? 


HINT:
The proper Informat for this is (dollar8.).


SOLUTION:
Data Char4;
Set Char;
Amt = Input(Amount, Dollar8.);
Run;


Fill out my online form.

Already a member? Go to member's area.