NCSS
Macros
NCSS has an interactive (point and click) user
interface which makes in easy to learn and use. At times, however, it is
necessary to repeat the same steps over and over. When this occurs, a
batch system becomes more desirable. NCSS 2007 includes a macro system
that utilizes a batch
language with over 45 commands that lets you create a
macro (script or program)
and then run the macro. With the click of a single button, you can have
the program run a series of procedures. You may record a macro by saving
the steps as you complete an analysis or write your own script. This
tool allows you to call and run an NCSS routine from within another
environment.
[Back to NCSS]
[Back to NCSS
Procedure List]
[Back to NCSS Upgrade Page]

Below are some example macros:
Example 1 - Automatically Run a
Procedure
This macro opens a dataset and
calculates descriptive statistics on the first five variables of that
dataset.
'*** Open a dataset
DataOpen "C:/Program Files/NCSS97/Data/Sample.s0"
'*** Load the Descriptive Statistics procedure
'*** Note that the default values are used.
LoadProc DescStat
'***
Specify that the first five variables are to be analyzed
Option DescStat 1 "1:5"
'***
Run the analysis
RunProc DescStat
Example
2 - Run Several Procedures
This macro opens a dataset,
calculates descriptive statistics on the first two variables, and then
runs a linear regression using those two variables.
DataOpen "C:/Program
Files/NCSS97/Data/Sample.s0"
LoadProc DescStat
Option DescStat 1 "1:2"
RunProc DescStat
LoadProc LinReg
Option LinReg 204 1
Option LinReg 205 2
RunProc LinReg
Example 3 - Simple Looping
This macro opens a dataset and
calculates descriptive statistics on the first five variables of that
dataset. Unlike Example1, this macro uses a simple loop to step through
the five variables.
Notice that the loop finishes once
the variable I# is equal to '5'.
DataOpen "C:/Program
Files/NCSS97/Data/Sample.s0"
I#=0
Flag1:
I#=I#+1
LoadProc DescStat
Option DescStat 1 I#
RunProc DescStat
IF I#<5 GOTO Flag1
Example 4 - Multiple Analyses Using
Filters
This macro opens a dataset and runs separate simple
linear regression analyses and scatter plots for three groups within the
dataset. The three groups are defined be the ‘Iris’ variable in the
dataset. The macro finds the levels of the ‘Iris’ variable and uses the
resulting values to determine the groups. Thus, the macro does not
require knowledge of the group names nor does it require knowledge of
the number of groups to be analyzed.
'Open
the FISHER.S0 database. %p% is replaced by the folder that
'was used for installation.
DataOpen "%p%\Data\FISHER.S0"
'Obtain the unique values of the Iris variable and put them in C21
VarTrans C21 "Uniques(Iris)"
RunTrans
'Obtain
the number of unique Iris values using C21
NumRows C21 n1#
'Loop
through the unique Iris values for grouping
I1# = 1
Flag1:
GetCell C21 I1# IrisGroup$
'Filter
the values according to the Iris variable
LoadProc Filter
LoadTemplate Filter "Example5_Macro"
IrisFilter$ = "Iris = " & IrisGroup$
Option Filter 3 IrisFilter$
RunProc Filter
UnLoadProc Filter
'Run
the Linear Regression procedure for the filtered group
LoadProc LinReg
LoadTemplate LinReg "Example5_Macro"
RunProc LinReg
UnLoadProc LinReg
'Run
the Scatter Plot procedure for the filtered group
LoadProc ScatPlot
LoadTemplate ScatPlot "Example5_Macro"
RunProc ScatPlot
UnLoadProc ScatPlot
'Loop
through the unique Iris values for grouping
I1# = I1# + 1
IF I1# > n1# GOTO Flag2
GOTO Flag1
'Turn
Filter Off
Flag2:
LoadProc Filter
Option Filter 1 0
RunProc Filter
UnLoadProc Filter
'End of
Macro
Print "MACRO COMPLETE"
|