Recording Macros - Automatic Programming
Statistica provides a comprehensive selection of facilities for recording macros to automate repetitive work or to be used as a means to automatically generate programs for further editing and modification. The macro (Statistica Visual Basic) programs recorded by these facilities can be saved to be run "as is," or they can be used as the "building blocks" for more complex and highly customized Visual Basic application programs.
There are three categories of macros that can be automatically created as you run Statistica:
- Analysis Macros
- First, you can record simple Analysis Macros from an analysis to record the settings, selections, and chosen options for that specific analysis. [Note that the term "analysis" in Statistica denotes one task selected either from the Statistics or Graphs tab or menu, which can be very small and simple (e.g., one scatterplot requested from the Graphs menu), or very elaborate (e.g., a complex structural equation modeling analysis selected by choosing that option from the Statistics tab or menu and involving hundreds of output documents).] After selecting any of the Statistical options from the Statistics tab or menu or graphics options from the Graphs tab or menu, all actions such as variable selections, option settings, etc. are recorded "behind the scenes;" at any time you can then transfer this recording (i.e., the Visual Basic code for that macro) to the
Visual Basic program editor window. Note that the Create Macro command is available from every analysis via the Options menu or the shortcut menu (accessed by right-clicking the analysis button) when the respective analysis is minimized.
Also, your choice of data files, as well as case selection conditions and the weight variable, are recorded as long as those options are selected in the analysis dialog (not from the File menu or the status bar). One such "stand alone" macro is created for each analysis and these macros are not "put together" automatically by Statistica (in fact they cannot be "mechanically" combined without some editing since each of them represents a stand-alone program that starts with the appropriate declarations, etc.).
The recording of Analysis Macros begins automatically whenever a new analysis is started from the Statistics or Graphs menu. Anything that "happened" before that is not recorded in the Analysis Macro. Thus, your specific selection of the input data file is not recorded (the Analysis Macro always assumes that it is to be executed on the current active input data file) unless that choice is made by clicking the Open Data button on the respective analysis dialog. Neither are any operations recorded that you may perform on the input data file, such as sorting the data, subsetting of variables and/or cases, etc.
- Master Macros (Logs)
- Second, you can record a
Master Macro or Master Log of your entire session that may consist of several or many analyses; this recording will "connect" analyses performed with various analysis options from the Statistics or Graphs menu. However, unlike simple Analysis Macros, you can turn the recording of Master Macros on or off. The Master Macro recording will begin when you turn on the recording, and it will end when you stop the recording. In between these actions, all file selections and most data management operations are recorded, as are the analyses and selections for the analyses, in the sequence in which they were chosen.
The most common application of the Master Macro would be to start Statistica, start the Master Macro recording by selecting Start Recording Log of Analyses (Master Macro) from the Tools - Macro menu, and then continue with the analyses. For example, you can compute descriptive statistics, perform some multiple regression analyses, make several histograms and scatterplots, etc. Note that during the analysis, you will see the floating Record toolbar to remind you that you are currently recording a Master Macro.
Finally, you stop the recording by either clicking the stop button on the floating Record toolbar or by selecting Stop Recording from the Tools - Macro menu. At that point, the Visual Basic program that represents all actions performed or selections made during the Master Macro recording will be transferred into a Statistica Visual Basic editor window. When you run this macro "as is," the exact same analyses will be repeated (with some exceptions resulting from the logic of creating reusable programs from sequences of interactive operations performed by the user, described below).
- Keyboard Macros
- When you select Start Recording Keyboard Macro from the Tools - Macro menu, Statistica will record the actual keystrokes you are entering via the keyboard. The floating Record toolbar will be visible as a reminder that a recording "session" is in progress.
When you stop the recording by either clicking the stop button on the floating Record toolbar (see above) or by selecting Stop Recording from the Tools - Macro menu, a Statistica Visual Basic editor window will open with typically a very simple program containing a single SendKeys command with symbols that represent all the different keystrokes you performed during the recording session.
Note: this type of macro is very simple in the sense that it will not record any context in which the recorded keystrokes are pressed and will not record their meaning (i.e., commands that these keystrokes will trigger), but this feature makes them particularly useful for some specific applications. For example, it can be very useful when it is attached to a keyboard shortcut (select Customize from the Tools menu to display the Customize dialog box; then select the Keyboard tab, where you can attach the program to a shortcut key) where it could be used, for example, to quickly reenter long text, a formula, a selection of variables, or a large number of options (via keystrokes) on some complex dialog.All three follow the identical syntax and can be modified at a later time, but because of the different ways in which each of them is created, they offer distinctive advantages and disadvantages for specific applications.
Recording Simple Macro (SVB) Programs, Documenting an Analysis