Previous Page | Next Page

SAS Component Language Dictionary

DECLARE



Declares variables and specifies their data types
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-n argument-n>;

data-type

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 in characters. The default length is 200, while the maximum is 32,767. 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. The STRING data type is an alias of the CHAR data type.

'LIST'

is for variables that can reference an SCL list.

'NUM'

is for variables that can contain numeric values.

'OBJECT'

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]

class-name

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 one or more constants and/or one or more variable names. The constants and/or variable names should be separated by spaces. When initializing lists, you can use either braces ({ and }) or brackets ([ and]) to enclose a series of list items. Variable names can be any of the following:

variable

variable = initial-value

variable = expression

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

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

listname2=[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 in SCL Programs.

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.

You can use either braces ({ and }) or brackets ([ or ]) to enclose a series of list items when you initialize an SCL list. For example, both of the following list definitions are valid:

dcl list x = {1,2,3};
dcl list z = [4,5,6];


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 a pop-up menu      */
/* when you press the ENTER key.      */

  dcl list myPopMenuList;
  control enter;

/* Initialize a list with three pop-menu items: Select 1, Numeric */ 
/* and Character. Define a separator between items  */ 
/* 'Select 1' and 'Numeric'.   */
  myPopMenuList = { {text='Select 1',
             helpText='This is a selection.',
             mnemonic='S',
             classifier = 107},
         "-",
         "Numeric",
         "Character"};

   return;
main:
 rc = popmenu (myPopMenuList);
 put rc=;
 return;

term:
 /* Delete myPopMenuList recursively to avoid a memory leak */
 rc = dellist ( myPopMenuList, 'y');
 return;

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


See Also

ARRAY

LENGTH

USECLASS

Previous Page | Next Page | Top of Page