Last chance,
1) the first command just makes an original data source in long format.
2) the second command introduces an index for the number of the event for each ID. the number of events does not need to be equal for each ID. but, if some ID's have less events they will have missing values in the wide table format.
3) the third command takes advantage of the index and the ID columns in order to split the table the way you asked for it. one column for each event and variable and each row represents just one ID.
on your data you just need to run the last two command.
names default to here(1);
// source data table
dt = New Table( "Long",
Add Rows( 7 ),
New Column( "ID",
Numeric,
Continuous,
Format( "Best", 5 ),
Set Values( [1, 1, 1, 2, 2, 3, 3] )
),
New Column( "Var1",
Numeric,
Continuous,
Format( "Best", 12 ),
Set Values( [1, 1, 1, 0, 0, 1, 1] )
),
New Column( "Var2",
Numeric,
Continuous,
Format( "Best", 12 ),
Set Values( [1, 1, 0, 1, 1, 1, 0] )
),
New Column( "Outcome",
Numeric,
Continuous,
Format( "Best", 12 ),
Set Values( [0, 0, 1, 1, 1, 0, 0] )
)
);
// add index column for spliting - no need to sort the table first
dt << new column ("index", formula(Sum( :ID[Index( 1, Row() )] == :ID ) ) );
// now split by index and group by ID
dt << Split(
Split By( :index ),
Split( :Var1, :Var2, :Outcome ),
Group( :ID ),
Output Table( "Wide" )
);