Chapter Contents |
Previous |
Next |
DECLARE |
Alias: | DCL |
Category: | Declarative Statement |
Syntax | |
Details | |
Comparisons | |
Examples | |
Defining a Constant List with a Sublist | |
See Also |
Syntax |
DECLARE|DCL data-type-1 argument-1 < . . . ,data-type-nargument-n >; |
The following are valid data types:
'CHAR
<(
n)
>''LIST'
'NUM'
'OBJECT'
Note: The compiler cannot validate attributes or methods
for objects declared with the OBJECT keyword (generic objects). Consequently,
using generic objects is less efficient (possibly up to 25 percent less efficient)
than declaring objects with the CLASS or INTERFACE keyword. See Objects
for more information.
Type: Character
variable
variable = initial-value
variable = expression
variable-1 - variable-n = (value-1,...,value-n)
listname={value-1,...,value-n }
Constants have the following form:
constant-n<=value-n>
Type: Character or Numeric (for variables). Type: Character (for constants). |
Details |
The DECLARE statement declares a variable of any SCL data type. DECLARE can be used within a DO, SELECT, or USECLASS block to define variables that are available only within that block. This enables you to enforce variable scoping, because variables that you declare within a DO, SELECT, or USECLASS block are local to that block.
You can use the DECLARE statement to declare any type of array. However, arrays that are declared with the DECLARE statement are all temporary arrays. See Using Temporary Arrays to Conserve Memory.
Although you can use the LENGTH statement to declare numeric and character variables, you might want to use the DECLARE statement in order to enforce variable scoping.
Place DECLARE statements either before the first labeled section of an SCL program or inside a DO or SELECT block.
Comparisons |
For details about the LENGTH statement in the base SAS language, see SAS Language Reference: Dictionary.
Examples |
dcl char s; dcl num x y; dcl char s, num x y; dcl char(10) ar[3] x y z; dcl list mylist; dcl sashelp.fsp.collection.class obj3; dcl object obj4; dcl num m n, char(300) string, list newlist;
Each variable or array can be followed by an initial value or expression. The following example declares and initializes various variables and arrays.
dcl num x=1 y=20+x; dcl num i1-i4=(1, 2, 3, 4); dcl num arr(3)=(1, 2, 3); dcl char(10) s='abc'; dcl char sarr(3)=('abc', 'def', 'ghi'); dcl list mylist = {1, 'abc', 2, 'def'}; /* Initialize a list */ dcl list l = (100, 'abc', 200);
Defining a Constant List with a Sublist |
A constant list can be defined with a sublist.
init: /*To edit a frame. As the frame runs,*/ /*it will display */ dcl list l ; /* a pop-up menu when you hit the ENTER key.*/; control enter /* Initialize a list with three pop-menu items: Select 1, Numeric*/ /*and Character. This will also define a separator between item*/ /*'Select 1'and 'Numeric'. */ list = { {text='Select 1', helpText='This is a selection.', mnemonic='S', classifier = 107}, "_", "Numeric", "Character"}; return; main: rc = popmenu (list); put rc=; return; term: /* Delete the list recursively to avoid a memory leak */ rc = dellist ( list, 'y'); return;
Note: The form of the physical filename depends on the
host operating
system.
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.