0% found this document useful (0 votes)
29 views13 pages

Sas Create Date Dim

The document discusses creating a date dimension table in SQL and importing it into SAS. It creates a DateSurrogates table with an OrderDate primary key, Surrogate autoincrement column, and DateKey integer column. DateKey is populated by inserting distinct OrderDate values and updating null DateKey values. The table is imported into SAS. SAS date/time functions and formats for working with date dimensions are also covered.

Uploaded by

sookhoor
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views13 pages

Sas Create Date Dim

The document discusses creating a date dimension table in SQL and importing it into SAS. It creates a DateSurrogates table with an OrderDate primary key, Surrogate autoincrement column, and DateKey integer column. DateKey is populated by inserting distinct OrderDate values and updating null DateKey values. The table is imported into SAS. SAS date/time functions and formats for working with date dimensions are also covered.

Uploaded by

sookhoor
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Creating the Date Dimension

Using SQL and SAS to process


dates.
Base E-R Diagram
Create DateSurrogates Index
CREATE TABLE DateSurrogates
(OrderDate Date
CONSTRAINT pk PRIMARY KEY,
Surrogate AUTOINCREMENT,
DateKey Integer);
Create Date Key
INSERT INTO DateSurrogates
(OrderDate)
SELECT DISTINCT OrderDate
FROM OrdersCopy
WHERE OrderDate
NOT IN (SELECT OrderDate FROM
DateSurrogates);
Update DateKey
UPDATE DateSurrogates SET DateKey =
Surrogate
WHERE DateKey IS Null;
DateSurrogatesTable
DateSurrogates:
 OrderDate Date/Time
 Surrogate Autoincrement
 DateKey Integer
Importing Into SAS
PROC IMPORT
OUT= WORK.CUSTOMER
DATATABLE= "DateSurrogates“
DBMS=ACCESS2000 REPLACE;
DATABASE="C:\DataWarehousing04s\ET
L\PremiereExtractExample.mdb";
RUN;
Results of Proc Contents
----Alphabetic List of Variables and Attributes-----
# Variable Type Len Pos Format Informat Label
3 DateKey Num 8 16 11. 11. DateKey
1 OrderDate Num 8 0 DATETIME20. DATETIME20. OrderDate
2 Surrogate Num 8 8 11. 11. Surrogate
SAS Date and Time Functions
and Formats
SAS has a number of useful functions for
working with dates and times. Their options
depend on the data type of the variable.
 DATETIME stores both the date and time

 DATE stores date information (in days from

January 1, 1960)
 TIME stores time information (in

seconds.fraction)
Functions
Functions take values and convert the
way the data is stored
Function Use
Datapart Takes a datetime attribute, extracts
the date part and stores it as a date
attribute
Timepart Takes a datetime attribute, extracts the
time part and stores it as a Time attribute
Functions
Function Use Use
Put(attribute, format) Returns a (character) value
using a specified format.
Input(attribute, informat) Returns the value produced
when a SAS expression is
read using a specified
informat.
Formats and Informats
Formats determine how a variable is
displayed; informats determine how a
variable id read. The tend to be similar.
FORMATNAMEw.d
Formats and Informats always contain a
period (.)
SAS makes assumptions about the best
display for a given w.d specification
Some Useful Formats
YEARw. Writes date values as the year
MONNAMEw. Writes date values as the
quarter of the year
DOWNAMEw. Writes data values as the the
name of the day of the week
Writes date values as the
QTRw.
quarter of the year
writes dates as the Julian day of
JULDAYw. the year (yyddd). For w=3
the output is ddd.

You might also like