Reshape SAS data set

If I have a dataset that is structured like this:

cat1  time    var_1   var_2   var_3
0     pre      8      12      7
0     post     3      2       9
1     pre      6      11      1
1     post     9      4       8

How can I reshape it to look like this:

          0pre   1pre   0post   1post
var_1      8     6        3      9
var_2      12    11       2      4
var_3      7     1        9      8

I’m trying different things with proc transpose but can’t figure it out.

>Solution :

Seems simple enough.
Just need ID and VAR statements.
But don’t list CAT1 first since variable names cannot START with a digit.

proc transpose data=have out=want delim=_;
  id time cat1;
  var var_1-var_3 ;
run;

Result

Obs    _NAME_    pre_0    post_0    pre_1    post_1

 1     var_1        8        3         6        9
 2     var_2       12        2        11        4
 3     var_3        7        9         1        8

Leave a Reply