12-03-2012 02:50 PM
I know that you can stack variables Using the DATA Step, SET statement for different data sets. But how do you stack specific columns in the same data set?
I have variables x1 to x10 (with multiple observations) in a data set. And I want to stack them into two columns: (col 1: x1, x3, x5, x7, and x9 and (Col 2): x2, x4, x6, x8, and x10
Please note that I am not trying to make a "wide" format dataset into a "long" format. Just trying to stack the columns one after the other ...
Can't seem to figure this one out.
12-03-2012 03:04 PM
It is long to wide, just with two different sets of variables.
Does the order matter for the observations?
One long way...
set have (keep= x1 x2 rename=(x1=col1 x2=col2))
have (keep= x3 x4 rename=(x3=col1 x4=col2));
array one(5) x1 x3 x5 x7 x9;
array two(5) x2 x4 x6 x8 x10;
do i=1 to 5;
drop i x:;
12-03-2012 03:09 PM
Thank you. But I tried this method and it does not work.
The ARRAY method you proposed takes the first observation from x1, x3, x5, x7, x9 and puts them in col1. Then it does the same for observation 2, etc. But this not stacking the columns. The order is important, and I want col1 to have all x1 values first, then all x3 values, x5, x7, x9
And the same for col 2: stacked values for x2 x4 x6 x8 x10
Need further help from the community? Please ask a new question.