RATS 11.1
RATS 11.1

LOCAL     datatype   list of names
 

Creates local variables within a PROCEDURE or FUNCTION. Use DECLARE for global variables and TYPE for procedure parameters. Local variables can be any of the legal RATS Data types. Note that you can include dimension fields for arrays as part of the LOCAL instruction—it is no longer necessary to use a separate DIMENSION instruction to dimension the array.

Parameters

datatype

The data type you want to assign to the listed variables. For instance, REAL, RECTANGULAR, or VECTOR[SERIES].

list of names

The list of variables that will have datatype. Separate the names with blanks. Symbolic names must be unique—if you attempt to assign a new type to a name already in use as a local variable, you will get an error message.
 

You can also set the dimensions of an array at the time you declare it, by using a dimension field instead of simply the variable name­—just provide the dimensions for the array in parentheses immediately after the variable name. Arrays can also be dimensioned later (or redimensioned) using DIMENSION. The dimensions can use PROCEDURE or FUNCTION parameters or options.

Description

Any variable (other than a PROCEDURE parameter or options or FUNCTION parameter) in a RATS program is a global variable unless you state otherwise. You can use a global variable within any part of a program, including PROCEDURES and FUNCTIONS. Global variable names must be unique—you cannot define two different global variables with the same name (even if they are of different types) within a particular program. Also, within a particular program or session, you cannot redefine an existing global variable as a different type. For instance, you cannot redefine a VECTOR as a REAL.

 

Procedures and functions, however, may have local variables as well as globals. These are only recognized within the procedure which defines them. RATS keeps global and local variables completely separate, so a local variable can have the same name as a global one. If a name conflict arises within a procedure, the local variable is used.

 

If you plan to use a single PROCEDURE or FUNCTION in many different programs, it is a good idea to write the procedure using only parameters, local variables, procedure options, and variables that RATS defines. That way there is no possibility that your procedure will conflict with the names of global variables used in the main program.

 

Note that RATS does not release the memory space for local series and local arrays when you exit the procedure. If you find it necessary to release the space before returning, use the instruction RELEASE.

Example

These are the first actual program lines for the @DFUNIT procedure. With the exception of DFUNIT itself and %%AUTOP, all the variables defined by the TYPE, OPTION and LOCAL instructions are part of the DFUNIT's "namespace", that is, they are recognized only here will cause no problems if used in other procedures or as global variables. %%AUTOP is intentionally defined using DECLARE so it will be visible outside the procedure.

 

procedure dfunit series start end

type series    series

type integer   start end

*

option choice  det                  2  none constant trend

option switch  ttest                1

option switch  print                1

option string  title

 

option integer lags

option integer maxlags

option choice  method            1 input aic bic hq ttest gtos

option real    signif      .10

 

option switch  intercept        1

option switch  trend                0

*

local integer  startl endl nobs tag

local series   s sdiff strend

local real     teststat fiddle

local string   descript lmethod

local vect     critvalues

local integer  dettrend detconstant

local string   ltitle

local integer  maxlag znobs bestlag lag tag

local real     ic icmin icmult

local report   dfreport

local vect[int] detlist

declare integer %%autop


 


Copyright © 2026 Thomas A. Doan