SAMPLE command
Draws a sample of records using either the record sampling or monetary unit sampling method.
Syntax
Note
The syntax does not include filtering (IF statements) or scope parameters because applying these options compromises the validity of a sample.
Fixed interval selection method
SAMPLE <ON> RECORD INTERVAL interval_value <FIXED initial_value> {RECORD|FIELDS field_name <...n>} TO table_name <OPEN> <APPEND> <LOCAL>
Cell selection method
SAMPLE <ON> RECORD CELL INTERVAL interval_value <RANDOM seed_value> {RECORD|FIELDS field_name <...n>} TO table_name <OPEN> <APPEND> <MERSENNE_TWISTER> <LOCAL>
Random selection method
SAMPLE <ON> RECORD NUMBER sample_size <RANDOM seed_value> <ORDER> {RECORD|FIELDS field_name <...n>} TO table_name <OPEN> <APPEND> <MERSENNE_TWISTER> <LOCAL>
Parameters
Note
Do not include thousands separators when you specify values.
Name | Description |
---|---|
ON RECORD | Use record sampling. |
INTERVAL interval_value FIXED initial_value | CELL INTERVAL interval_value | NUMBER sample_size |
INTERVAL interval_value FIXED initial_valueUse the fixed interval selection method. An initial record is selected and all subsequent selections are a fixed interval or distance apart – for example, every 20th record after the initial selection.
CELL INTERVAL interval_valueUse the cell selection method. The data set is divided into multiple equal-sized cells or groups, and one record is randomly selected from each cell. The interval_value dictates the size of each cell. Specify the interval value that was generated by calculating the sample size. NUMBER sample_sizeUse the random selection method. All records are randomly selected from the entire data set. Specify the sample size that was generated by calculating the sample size. |
RANDOM seed_value optional |
Note Cell and random selection methods only. The seed value to use to initialize the random number generator in Analytics. If you specify a value of zero ('0'), or omit RANDOM, Analytics randomly selects the seed value. |
ORDER optional |
Note Random selection method only. You can only use ORDER when specify FIELDS. Adds the ORDER field to the output results. This field displays the order in which each record is randomly selected. |
RECORD | FIELDS field_name <...n> |
|
TO table_name |
The location to send the results of the command to:
|
OPEN optional |
Opens the table created by the command after the command executes. Only valid if the command creates an output table. |
APPEND optional |
Appends the command output to the end of an existing file instead of overwriting it. Note You must ensure that the structure of the command output and the existing file are identical:
Analytics appends output to an existing file regardless of its structure. If the structure of the output and the existing file do not match, jumbled, missing, or inaccurate data can result. |
MERSENNE_TWISTER optional |
Note Cell and random selection methods only. The random number generator in Analytics uses the Mersenne-Twister algorithm. If you omit MERSENNE_TWISTER, the default Analytics algorithm is used. Note You should only use the default Analytics algorithm if you require backward compatibility with Analytics scripts or sampling results created prior to Analytics version 12. |
LOCAL optional |
Saves the output file in the same location as the Analytics project. Note Applicable only when running the command against a server table with an output file that is an Analytics table. |
Examples
Draw a record sample
You are going to use record sampling to estimate the rate of deviation from a prescribed control in an account containing invoices.
After calculating a statistically valid sample size, you are ready to draw the sample. You are going to use the random selection method.
The example below:
- Samples the open Analytics table
- Uses the random selection method with a seed value of 123456
- Specifies a sample size of 95 records
- Includes only specified fields in the output table
- Specifies that the random number generator in Analytics uses the Mersenne-Twister algorithm
SAMPLE ON RECORD RANDOM 123456 NUMBER 95 FIELDS RefNum CustNum Amount Date Type TO "Ar_record_sample" OPEN MERSENNE_TWISTER
Remarks
Note
For more information about how this command works, see the Analytics Help.