Previous Topic: 2.2 A SAS ProgramNext Topic: Understanding the CA MICS Database


2.3 SAS Syntax

The rest of this guide builds on your understanding of SAS
and CA MICS terminology:

o The basic unit of data in SAS is the data value, which is
  an individual measurement for a variable. For example, the
  vertical collection of data values in the AGE column below
  is a variable. A SAS variable is a CA MICS data element.

o An observation is a collection of data values associated
  with some single entity. Six observations are illustrated
  in the six rows below. A SAS observation is a CA MICS
  record.

o A SAS data set is a collection of observations of the same
  type. Therefore, all the observations below make up a SAS
  data set or a CA MICS file.

           +-------+---------------------------+
           |       |         VARIABLE          |
           |       +--------+-------+----------+
           |  OBS  |  NAME  |  AGE  |  WEIGHT  |
           +-------+--------+-------+----------+
           |   1   |  JOHN  |   15  |    139   |
           |   2   |  MARY  |   12  |     59   |
           |   3   |  JOE   |    8  |     88   |
           |   4   |  JACK  |   33  |    185   |
           |   5   |  BILL  |   17  |    140   |
           |   6   |  DENA  |    4  |     28   |
           +-------+--------+-------+----------+

Figure 2-1.  Example of a SAS Data Set

SAS data sets are self documenting.  That is, a SAS data set
carries its own format and data value naming information, if
that information has been defined.  CA MICS files have format
and label descriptions for each CA MICS data element.

Variable names can be up to 8 characters long.  The first
character must be a letter. (Underscores should not be used
as the first character of a variable, since they have special
significance in CA MICS.)  Special characters and blanks are
not allowed.

Blanks are used to separate or delimit variables or constants
in SAS statements.  If you are using a special character such
as '='= or ';' in a SAS statement, it also serves as a
separator.

A SAS statement begins with a keyword or variable name and
ends with a semi-colon (;).  Examples of keywords are DATA,
PROC, SET, IF, and BY.

SAS statements are free format.  Several statements can be
written on a single line, and one statement can continue over
several lines.  A word can be broken at the end of one line
and continued on the next line (but be careful not to
introduce blanks since they are delimiters).

Since you will most likely be using TSO/ISPF to enter
programs and you will want them to be easy to read and edit,
we recommend that you use one statement per line and indent
to distinguish such things as DATA STEPS, PROC STEPS,
IF-THEN-ELSE constructs, and loops.

Comments can be entered anywhere, except within an
IF-THEN-ELSE construct, as independent statements beginning
with an asterisk followed by the comment text and ending with
a semi-colon.  They may also be constructed beginning with a
/*  followed by one or more lines of comment text and ending
with a */. Here are two examples:

/* COMMENT  THIS IS  A SAS PRIMER */
* TO HELP YOU LEARN SAS;

Variables are defined in the order in which they first
appear.  If you have to refer to lists of variable names when
creating and manipulating SAS data sets, the VAR statement
shortens the amount of writing that must be done:

o If variables are named (Q1, Q2, Q3, Q4), you can refer to
  them as VAR Q1-Q4, separating the first and last names with
  a minus sign.

o If you have a list of variables (Q1, Q2, A, B, C, D), you
  can refer to them as VAR Q1--D, separating the first and
  last names with two minus signs.

o You can refer to all currently defined variables like this:

  VAR _ALL_;

Constants can be either numeric or character.  Numeric
constants can be any number between 10(-73) and 10(73).  The
values 1, 87.65 and -23E3(-23x10(3)), which means -23000, are
all numeric constants.