Hello,
I have sorta a complex transpose I need to do I neet to take something like this
Stone1_row_1 | Stone1_row_2 | Stone1_row_3 | Stone2_row1 | Stone2_row2 | Stone2_row3 |
and make it look like this
Stone1_row_1 | Stone1_row_2 | Stone1_row_3 |
Stone2_row1 | Stone2_row2 | Stone2_row3 |
Does anybody know an easy way to do this.
Thanks for the help,
Preston
Are those VALUES or Variables?
Do you want this in a report or a data set? Since SAS datasets only have one variable per column then that request may not make sense.
What will you be doing with the result if you want a data set?
From what you show you may be better served for many purposes with a set structured as
Stone Row Value
1 1 <whatever is currently in stone1_row_1>
1 2 <next value>
1 3 <next value>
2 1 <>
2 2 <>
2 3 <>
Those are values, and I would like it in a data set. I would like to have the rows horizontal and the stones verticle.
Stone_nbr row1 row2 row3
1 3 4 5
1 2 2 2
1
2
2
2
What are your variable names? Actual example data helps things go better. This link https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show you how to create a data step that you can post here to create a few rows of data.
Im sorry but because of security reasons I cant post exactly what the data looks like but I hope this helps. The data looks something like this;
DWID | Stone1_row_1 | Stone1_row_2 | Stone1_row_3 | Stone2_row1 | Stone2_row2 | Stone2_row3 |
1 | 1 | 3 | 6 | 3 | 9 | 9 |
2 | 2 | 3 | 3 | 4 | 8 | 7 |
3 | 3 | 5 | 7 | 3 | 8 | 4 |
4 | 4 | 6 | 3 | 7 | 7 | 3 |
And I would like it to look like this
DWID | Stone_NBR | Row_1 | Row_2 | Row_3 |
1 | 1 | 1 | 3 | 6 |
1 | 2 | 3 | 9 | 9 |
2 | 1 | 2 | 3 | 3 |
2 | 2 | 4 | 8 | 7 |
3 | 1 | 3 | 5 | 7 |
3 | 2 | 3 | 8 | 4 |
4 | 1 | 4 | 6 | 3 |
4 | 2 | 7 | 7 | 3 |
This works for your example data:
data want (keep=dwid stone_nbr Row_1-Row_3 );
set have;
array t {2,3} stone1: stone2:;
array r {3} row_1 row_2 row_3;
do stone_nbr= 1 to 2;
do row= 1 to 3;
r[row] = t[stone_nbr,row];
end;
output;
end;
run;
Note that your previous answer to my question about variables versus values wasn't quite correct. You posted variable names, not values.
I don't know anything of your requirement and real data - but IMO most scenarios benefit from even transpose your Row variables to rows:
DWID - Stone_NBR - Row_NBR - Row_Val (whatever that is)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.