Splits vectors into individual vectors according to levels of a factor (R.W. Payne).
||Factor identifying the unstacked data sets|
||Factors identifying how the units of the unstacked data sets should be matched|
||Factors defined to identify these units in the unstacked vectors|
||Which missing values to include (
||Vectors to be unstacked|
||Level or label of the
UNSTACK allows you to split up (or unstack) vectors into individual vectors. The contents of the individual vectors are determined by a factor, specified by the
DATASET option. In the simplest case, each original (stacked) vector is split into several new (unstacked) vectors, one for each level of
DATASET. The process assumes that the sets are “replicate” sets of data. For example
DATASET might correspond to days on which identical sampling schemes were followed. In the most straightforward case, each set contains the same number of observations all stored in an identical order. However, if the observations are in different orders or if some are absent in some of the sets, you can use the
IDSTACKED option to specify one or more factors to identify the matching observations within the sets. The
IDUNSTACKED option then allows you to save new factors to indicate where the observations are stored in the new (unstacked) vectors. The unstacked vectors are all of the same length, and missing values are inserted for absent observations.
MVINCLUDE option controls the inclusion of missing values in the unstacked vectors, with the following settings:
||includes units with missing values for levels of the
||stacked vectors that correspond to data set indexes that do not occur in the data are defined and filled with missing values (otherwise these are left undeclared, and a warning is given).|
By default none of these are included.
There are three parameters.
STACKEDVECTOR lists the vectors (variates, factors or texts) that are to be split up.
DATASETINDEX specifies a level of the
DATASET factor for each member of the
STACKEDVECTOR list, and
UNSTACKEDVECTOR specifies a new vector to store the units of the
STACKEDVECTOR corresponding to that
DATASETINDEX. So, for example
UNSTACK [DATASET=Days] 5(Weight,Height);\
would put the weight measurements made on days 1-5 into
W5, respectively, and the height measurements into
H5. (The construct
5(Weight,Height) is equivalent to typing
Weight five times and then
Day five times, and the
1,2,3,4,5 is repeated twice so that it matches the lengths of the other parameter lists.) This method of specification means that you are free to list the vectors and levels in whatever order is most convenient. For example
UNSTACK [DATASET=Days] (Weight,Height)5;\
lists them in group order rather one stacked vector at a time. If
DATASETINDEX is not specified, the levels of
DATASET are taken in order one at a time (and recycled if necessary).
Any restrictions on the vectors are ignored.
CAPTION 'UNSTACK example'; STYLE=meta FACTOR [LEVELS=31; VALUES=1...31,1...30] Day FACTOR [LABELS=!t(March,April); VALUES=31(1),30(2)] Month VARIATE [NVALUES=61] Rainfall,Temperature READ Rainfall,Temperature 2.7 11.7 2.9 7.6 1.7 8.0 4.2 9.4 4.1 3.7 0.2 11.4 2.5 6.3 3.0 11.9 0.3 4.5 0.6 10.4 3.0 11.3 0.3 7.3 4.2 12.0 2.5 10.0 3.9 9.0 1.2 4.6 1.4 5.7 3.7 11.8 2.9 11.9 2.7 10.4 0.9 3.0 4.7 10.4 3.5 6.0 3.4 9.2 3.3 5.6 4.8 7.5 1.9 11.7 0.9 10.3 1.1 3.4 0.2 5.7 1.0 4.1 0.1 6.0 3.2 11.0 0.6 4.4 1.2 11.2 1.7 9.1 1.4 3.6 3.1 8.2 3.0 9.7 0.9 7.3 1.8 3.6 3.7 12.5 3.9 7.9 1.4 9.3 4.6 12.2 0.8 4.6 1.9 5.8 3.1 8.8 3.6 11.5 2.8 8.4 2.8 11.7 0.3 6.1 4.5 4.5 4.2 6.2 1.6 12.5 2.7 5.8 2.7 5.5 2.7 9.6 1.8 5.8 0.4 9.1 0.8 3.6 : PRINT Month,Day,Rainfall,Temperature; DECIMALS=0,0,1,1 UNSTACK [DATASET=Month; IDSTACKED=Day; IDUNSTACK=Nday]\ 2(Rainfall,Temperature); DATASETINDEX='March','April';\ UNSTACKEDVECTOR=MarchRain,AprilRain,MarchTemp,AprilTemp PRINT Nday,MarchRain,AprilRain,MarchTemp,AprilTemp; DECIMALS=0,4(1)