10-29-2014 06:14 PM
I am working with a transaction type data set where there are multiple observations for individual children. Each child has a unique "child_id" and there are multiple observations, for which the child has an associated value for the variable TREATMENT. There may or may not be repeats for the values of TREATMENT.
There are around 80,000 children. There an indefinite number of TREATMENT paths based on around 30 TREATMENT types.
The following is similar to what the data currently looks like:
The following is just a brief example of what I would like the data to look like. The TREATMENT should only increment when the treatment type has changed.
Child Treatment_1 Treatment_2 Treatment_3 Treatment_4 Treatment_n
1 A C D B
2 B A B
Thank you for your insight
10-30-2014 05:24 AM
Another Solution with Data Step.
You need to have the data set, HAVE. to be pre-sorted by Child.
The array size is taken as 4 but can be extended as desired.
if first.Child then i = 1; t = Treatment; i + 1; end;
else if Treatment ^= t[i - 1] then do; t = Treatment; i + 1; end;
drop i Treatment;