Intro To Sas Prog Lang
Intro To Sas Prog Lang
Intro To Sas Prog Lang
[SAS is a registered trademark of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.]
Here is an example of reading data from a “permanent” You may use date constants or time constants in a SAS
SAS data set (in the SAS data library whose previously expression by writing the date or time enclosed in
defined libref is ‘MYLIB’): quotes, and followed by a D (date), a T (time), or DT
(date:time).
DATA EXAMPLE;
SET MYLIB.STUFF; THISDATE = ‘20Aug2001’D;
SLEEPTIME = ‘23:59:59.9’T;
Here is an example of creating a “permanent” SAS data FAISDODO = ‘21Aug2001 20:30’DT;
set (also in the SAS data library whose previously
defined libref is ‘MYLIB’): To read data that are date or time values, SAS has a
variety of informats. To write date or time values in
DATA MYLIB.TESTDATA; reports, SAS has numerous formats. SAS also has
SET SAMPLE1; several special functions for working with date or time
values. We’ll learn more about informats, formats, and
A SAS DATA statement instructs the SAS System to functions in another presentation.
create and name a SAS data set. It has the general
syntax: Summary
DATA data-set-name-1 (options-1) This short paper included some of a programmer's first
data-set-name-2 (options-2) steps toward learning about the SAS programming
... language. In particular, it covered the following items:
data-set-name-k (options-k) ; an overview of the SAS System, a few fundamental
ideas regarding SAS data sets, some preliminary
Many SAS data sets can be created in a single DATA concepts regarding DATA and PROC steps, and the
step. DATA step options include such things as: different kinds of data in SAS.
DROP= , IN= , FIRSTOBS= , KEEP= , OBS= ,
RENAME= , WHERE= , and others. Suggested References:
The two major functions of the DATA statement are: to
Ronald P. Cody & Raymond Pass, SAS Programming
signal the beginning of the DATA step, and to name the
By Example (1995)
data set(s) being created.
Lora D. Delwiche & Susan J. Slaughter, The Little SAS
Book: A Primer, Second Edition (1998)
When creating temporary SAS data sets, the data set
Frank DiIorio, SAS Applications Programming: A Gentle
name can be supplied by the programmer:
Introduction
SAS Institute Inc., SAS OnlineDoc, Version 8
DATA STUDENTS;
SAS Institute Inc., Getting Started With the SAS
INPUT NAME $ 1-14 SEX $ 15
System, Version 8
SECTION $ 17-19 GRADE;
SAS Institute Inc., SAS Language Reference:
DATALINES;
Concepts, Version 8
. . . data lines . . . ;
SAS Institute Inc., SAS Language Reference:
Dictionary, Version 8, Volumes 1 and 2
or, if the name is omitted in the DATA statement, the
SAS Institute Inc., SAS Procedures Guide, Version 8,
SAS System will provide a name (DATA1, DATA2,
Volumes 1 and 2
etc.):
DATA ;
INPUT NAME $ 1-14 SEX $ 15 Author Information.
SECTION $ 17-19 GRADE;
DATALINES; Tom Winn
. . . data lines . . . ; Texas State Auditor’s Office
P.O. Box 12067
A Few Words About Working With Dates and Times Austin, TX 78711-2067
Using SAS
phone: 512 / 936-9735
Whenever SAS reads date value inputs, it converts e-mail: twinn@sao.state.tx.us
them into integers. SAS dates are positive or negative
integers representing the number of elapsed days
between January 1, 1960 and the specified date.
Similarly, SAS converts time values into the number of
seconds since midnight of the current day. SAS
datetime values are the number of seconds since
midnight on January 1, 1960. Since dates and times
are numeric entities, one may use ordinary arithmetic to
determine elapsed time, or future/past dates and times.