cpander - 1 year ago 103

R Question

I've been trying to do something that's very easy to do in R in SAS. Basically, I have a table with *2n* columns and one row. I would like to have a table with *n* columns and two rows.

This is basically what I'm trying to do, in R:

`x <- c(1:10)`

y <- matrix(x, nrow = 2, ncol = 5, byrow = T)

Which takes us from:

`> x`

[1] 1 2 3 4 5 6 7 8 9 10

to:

`> y`

[,1] [,2] [,3] [,4] [,5]

[1,] 1 2 3 4 5

[2,] 6 7 8 9 10

So in SAS, let's say I have the following example dataset:

`data test;`

input v1 v2 v3 v4 v5 e_v1 e_v2 e_v3 e_v4 e_v5;

datalines;

1 2 3 4 5 6 7 8 9 10

;

run;

I am trying to make it such that e_v1 is actually row two of v1, etc. - in other words, I want to go from this one-row dataset (x in the R example above) to a two-row dataset (y in the R example above). Am I missing something obvious?

Thank you!

Answer Source

This is a solution for your example.

```
data tworow;
set test(keep=v:) test(keep=e: rename=(e_v1-e_v5=v1-v5));
run;
```