Professional Documents
Culture Documents
ARRAY TIME(0:5) A B C D E F;
ARRAY ABC[5];
Specifies initial values for the items in an array. In the first example,
DRINKSIZE ( 1 ) = SMALL = 8
In the second example,
CUPSIZE ( 1 ) = CUP1 - 8
you may not know the value of the largest index. You can
access these values using SAS functions. In this case, the
upper bound is set to the value DIM (arrayname) or DIM
(TIME), which is 6. Moreover, the function LBOUND
(arrayname) represents the lowest index in the specified
array and HBOUND (arrayname) represents the highest
index.
13 SAS ESSENTIALS -- Elliott & Woodward
Referring to Values in an Array
Once an array is created (such as TIME [ 1 : 6] ), you can
refer to a value in the array by specifying an index value,
and use that value in any common SAS statement. For
example,
NEWVAL=(TIME[5]/365);
DO ILOOP=l to 4; SUM=0 + 1;
Subsequent loops are:
SUM=SUM+ILOOP; SUM=1+2;
SUM=3+3;
SUM=6+4;
END; So,the final value of SUM at
the end of the loop is 10.
SUM=O;
DO WHILE(ILOOP LT 5);
SUM=SUM+ILOOP;
ILOOP+l;
END;
RETAIN SCORE;
29 SAS ESSENTIALS -- Elliott & Woodward
Setting Values in RETAIN
A statement that retains the values of several variables
could be
RETAIN TIME1-TIME10 SCORE VISITDATE;
By default, the initial value of retained variables is
missing. A statement to retain the value of SCORE, with
an initial value of 1, is
RETAIN SCORE 1;
In the following, CATEGORY has an initial value of NONE
and variables TIME1-TIME10 have initial values of 0.
RETAIN CATEGORY "NONE" TIME1-TIME10 0;
%MEND macroname;
End the SAS macro with a
%MEND statement.
43 SAS ESSENTIALS -- Elliott & Woodward
An explanation of how macro code works:
The information between the %MACRO statement and the
%MEND statement is a SAS macro routine consisting of SAS
code.
The macroname is the name you give to the macro that obeys
standard SAS naming conventions.
The parameter list indicates a way to "send" information into
the macro routine (illustrated in an upcoming example).
Within the SAS macro (between %MACRO to %MEND), the
variables referenced in the parameter list become macro
variables within the macro and may be referred to withthe
standard macro variable syntax and variablename.
%REPORT(SUBJ=001, DSN=C:\SASDATA\SUBJECTS);
Do the Hands
On Example on
P 184
%INCLUDE "C:\SASDATA\DMACRODISCLAIM.SAS";
These slides are provided for you to use to teach SAS using this book. Feel free to
modify them for your own needs. Please send comments about errors in the slides
(or suggestions for improvements) to acelliott@smu.edu. Thanks.