Basic Loops and Writing Results

Scripts can save you time by automating repetitive commands, compiling the results, and writing those results to a data file that you can review later. This example loops through multiple years and multiple CA sections (e.g., Section 1 is Pharmacology) to monitor trends over years.

 

\* This script provided without warranty

\* Example script with loop and datafile

 

=> FILE HCAPLUS

 

ECHO “Enter filename to store results:”

 

GET _Resultsfile LABEL=”Enter name of file”

GET commands present a dialog box to the user to collect the variable information.

OPEN <_Resultsfile> /w

 

IF (_$filerror <> 0) BEGIN

   ECHO “The file name specified could not be located.”

   ECHO “Exiting script.”

   EXIT

END

Optional error detection routine with ECHO messaging helps expose problems when running script.

_year = 2008

_yearlimit = 2017

@YEARLOOP

 => SET RANGE =_year

 IF (_year = _yearlimit) BEGIN

   ECHO “Processed all years.”

   EXIT

 END

 

 WRITE _year NOCR

 WRITE “;” NOCR

NOCR prevents the script from jumping to a new line for each entry.

_section = 1

 _sectionlimit = 81

@SECTIONLOOP

 IF (_section = _sectionlimit) BEGIN

   ECHO “Processed _section sections.”

   GOTO @JUMP

 END

 

=> S _section/SC

 WRITE _$LANS NOCR

 WRITE “;” NOCR

 _section = _section + 1

 GOTO @SECTIONLOOP

After searching the section number, the record count is written to the data file, and the section number is incremented.

@JUMP

 => DEL HIS Y

 _year = Year + 1

GOTO @YEARLOOP