3.62 mtra - Convert Vertical Data to Vector

Connect the items from the specified fields in f=, and save the string of items as a vector in a new column (referred to as transaction field). Specify the delimiter character of the items at delim=.

Format

mtra f= [s=] [k=] [delim=] [-r] [i=] [o=] [-nfn] [-nfno] [-x] [-q] [--help] [--version]

Parameters

f=

Specify field(s) (multiple fields can be specified) where the transaction fields are connected as an item.

 

NULL values will not be included in the vector.

k=

Key field name(s) (multiple items can be specified) of the character string pattern.

 

-r option cannot be specified with this parameter.

delim=

Specify the delimiting character (Space is used as the default delimiter).

-r

Reverse conversion

 

Convert transaction items column to vertically structured data.

Examples

Example 1: Basic Example

Combine the corresponding item for each customer in a string using a space as the delimiter, and save output in the column named transaction.

$ more dat1.csv
customer,item
A,a
A,b
B,c
B,d
B,e
$ mtra k=customer f=item:transaction i=dat1.csv o=rsl1.csv
#END# kgtra f=item:transaction i=dat1.csv k=customer o=rsl1.csv
$ more rsl1.csv
customer%0,transaction
A,a b
B,c d e

Example 2: Use hyphen (-) as item delimiter

$ mtra k=customer f=item:transaction delim=- i=dat1.csv o=rsl2.csv
#END# kgtra delim=- f=item:transaction i=dat1.csv k=customer o=rsl2.csv
$ more rsl2.csv
customer%0,transaction
A,a-b
B,c-d-e

Example 3: Convert items in descending sort order

$ mtra k=customer s=item%r f=item:transaction i=dat1.csv o=rsl3.csv
#END# kgtra f=item:transaction i=dat1.csv k=customer o=rsl3.csv s=item%r
$ more rsl3.csv
customer%0,transaction
A,b a
B,e d c

Related Commands

mvsort : Vector based transaction data can be processed by a set of commands (with mv as prefix) which handles vector data.

mcross : Rather than converting as transaction data, every item is saved separately as individual field in the output.

mtrafld : Create transaction data using “field name=value”.

mtraflg : Create transaction data as item with field names.