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 [8-17]


Attribute #5: Variable Format
Picture

Variable Format changes the display of the data.

Display of the data?

Yes. The variable format "masks" the data so that the display of the data is different than the values stored internally in the system.

Example
Picture

In this data set, Num1 and Num2 contain identical information.

They each contain a set of numbers from 10001 to 10010.

Now, let's take a look at how the variable format can change the display of the data.

Example

Data Display2;
Set Display;
Format Num2 Dollar10.;
Run;

A format called (Dollar10.) is applied to the variable Num2. 
Picture

The Display of Num2 is changed. It now includes the dollar sign ($) and the comma separator.

​E.g 10001 --> $10,001
Picture

(try it!)
​
IMPORTANT NOTE

Variable Format changes ONLY the display of the data. It does not change the internal data that is stored in SAS.

I.e. Internally, Num1 and Num2 still contain exactly the same data, which is the set of numbers from 10001 to 10010.

Let’s take a look at another example.

Example

Data Display3;
Set Display;
Format Num2 yymmdd10.;
Run;

In this example, a format called (YYMMDD10.) is applied to Num2. ​
Picture

The date format will display the numbers as dates instead.

E.g 10001 --> 1987-05-20
Picture

The concept of the date format will be explained in details in later modules.

Let’s take a look at one more example.

Example

Data Display4;
Set Display;
Format Num2 time8.;
Run;
Picture

In this example, a time format is applied to Num2. 

The variable will display the data as the time values instead.

E.g 10001 --> 2:46
​

SAS format is not the easiest concept to understand, especially for beginners.

There are many different formats for both numeric and character variables.

You will learn some of the most common formats in the next few modules.


Exercise

Copy and run the TRANSAC data set from the yellow box below.

The TRANSAC data set contains the following variables:
  • Order: Order number
  • Date: Date of the transaction
  • Time: Time of the transaction
  • Total: Total amount

Assign the appropriate formats to the Date, Time and Total variable. Create any data set or variable if needed.

What date were these transactions made?
Next

Need some help? 


HINT:
(YYMMDD10.) would be a good format for the date variable.


SOLUTION:
Data Transac2;
Set Transac;
Format Date yymmdd10. Time time5. Total dollar10.;
Run;

2012-01-08


Fill out my online form.

Already a member? Go to member's area.