Chapter Contents




Declares variables and specifies their data types

Alias: DCL
Category: Declarative Statement

Defining a Constant List with a Sublist
See Also


DECLARE|DCL data-type-1 argument-1 < . . . ,data-type-nargument-n >;

specifies the data types to assign. Multiple data types may be declared with one DECLARE statement. Use a comma to separate multiple data types. If you omit a comma between data types, then subsequent data type names are interpreted as variable names until the next comma is encountered.

The following are valid data types:

'CHAR <(n)>'
is for variables that can contain character values. Optionally, n is the length. Default: 200. Declaring a length for CHAR variables that will store values shorter than 200 characters can reduce the amount of memory required to store a program's variables.

is for variables that can reference an SCL list.

is for variables that can contain numeric values.

is for variables that can contain the identifier of a component.

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.  [cautionend]

is for variables that can contain the identifier of an instance of a particular class. It can be a one- to four-level name.

Type: Character

argument-1< . . . argument-n>
can be either one or more constants and/or one or more variable names. The constants and/or variable names should be separated by spaces. Variable names can be any of the following:


variable = initial-value

variable = expression

variable-1 - variable-n = (value-1,...,value-n)

listname={value-1,...,value-n }

Constants have the following form:

Type: Character or Numeric (for variables).

Type: Character (for constants).


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.


For details about the LENGTH statement in the base SAS language, see SAS Language Reference: Dictionary.


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.',
             classifier = 107},

 rc = popmenu (list);
 put rc=;

 /* Delete the list recursively to avoid a memory leak */
 rc = dellist ( list, 'y');

Note:   The form of the physical filename depends on the host operating system.  [cautionend]

See Also




Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.