Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading