Solutions Company Statit Training Home
 



ifexist( ) Function and @v[ ] Syntax

Abstract: An example illustrating the ifexist() function and the @v[] syntax

Product: Statit Custom QC

To check for the existence of a variable, you can use the ifexist( ) function. The syntax is:

ifexist("<Variable name>")

The function returns 0 if the variable does not exist. Otherwise it returns the variable id number.

So in a command you might do something like:

if ifexist("Temp") > 0 then let %cmd = "let temp = temp * 2"

Now you have a command that is based on the existence of a variable. How do you execute it? This is where you would use the @v[ ] syntax. This syntax allows you to drop the value of a temporary variable in a Statit macro just about anywhere, even as a command.

To execute this command you would:

let %cmd = " "
if ifexist("Temp") > 0 then let %cmd = "let temp = temp * 2"
@v[%cmd]

%cmd is first set to a space. This is important because the temporary variable %cmd will exsit as long as the current session of Statit is running. In Statit e-QC, this means that as long as you are logged in this variable exists. In this case, it may already exist when you run this macro. You need to make sure you control what is in it.

Next, if the condition is true, %cmd would be set to contain the command "let temp = temp * 2". If the condition is false, it is left blank.

And the third line simply puts the contents of %cmd on the next line of the macro. If it is a space, nothing happens. If it contains a command, the command is executed.

Here is another illustration of the use of ifexist( ):

To store the variable ID number of the variable Process_date in the temporary variable $var_id

let $var_id = ifexist("Process_date")

Another illustration of the @v[ ] syntax:

Suppose your database stores an Upper Control Limit (UCL) and a Lower Control Limit (LCL) but sometimes they are returned as missing. When they are there, you want them used in your command. Perhaps they are returned from the query in the variables UCL and LCL.

let #ucl = UCL(1) ## Subscript in case the variable has more than one case
let %ucl = " " ## Set to blank
if #ucl != #_sysmiss then %ucl = " /ucl = #ucl " ## Load the string if the value is not missing
let #lcl = LCL(1) ## Subscript in case the variable has more than one case
let %lcl = " " ## Set to blank
if #lcl != #_sysmiss then %lcl = " /lcl = $lcl " ## Load the string if the value is not missing
## Now you can use the two strings in a command.
gichart data by 2 @v[%ucl] @v[%lcl]

If you would like additional information, please call our Support staff at statit.support@conduent.com.