DATA Step, Macro, Functions and more

How to use proc transpose

Reply
Contributor
Posts: 40

How to use proc transpose

Hi,

 

I have this table

momrstd_ressta_res_rsqidskewret
 2.4930.0003.098-0.0850.478
15.324-0.1402.111-0.0410.283
24.694-0.1532.189-0.0530.317
35.122-0.1162.443-0.0620.429
45.763-0.0292.764-0.0580.444
56.116-0.0073.292-0.0570.352

I want to proc transpose to this:

 12345(5)-(1)
std_des5.3244.6945.1225.7636.1160.792 (49.55)
sta_des-0.140-0.153-0.116-0.029-0.007

0.133

(9.55)

_rsq2.1112.1892.4432.7643.292

1.181

(3.55)

ID-0.041-0.053-0.062-0.058-0.057

-0.015

(6.55)

skewret0.2830.3170.4290.4440.3520.069

I run: proc transpose data=data out=want; var std_des sta_des _rsq id skewret;run;

The result with proc tranpose has only COL1, I have no idea to fix it and I want to make a new Column = Column 5 - Column1 and have t-stat in (). 

Thank you so much for your help.

 

 

PROC Star
Posts: 1,760

Re: How to use proc transpose

Posted in reply to yotsuba88

You can't have numbers as variable names.

And proc transpose will not do calculations,

Apart from that, this does what you want:


data HAVE;
  set SASHELP.CLASS(obs=5) ;
  COLNAME=catt('VAR_',_N_);
run;

proc transpose data=HAVE out=TMP; 
  var NAME SEX AGE HEIGHT WEIGHT;  
  id COLNAME; 
run;

data WANT;
  set TMP;
  DIFF=VAR_1-VAR_2;
run;

 

 

 

Super User
Super User
Posts: 7,080

Re: How to use proc transpose

Posted in reply to yotsuba88

Seems pretty simple. Note that you will lose the rows (columns) where MOMR is missing.

data have ;
  input momr std_res sta_res _rsq id skewret;
cards;
. 2.493  0.000 3.098 -0.085 0.478
1 5.324 -0.140 2.111 -0.041 0.283
2 4.694 -0.153 2.189 -0.053 0.317
3 5.122 -0.116 2.443 -0.062 0.429
4 5.763 -0.029 2.764 -0.058 0.444
5 6.116 -0.007 3.292 -0.057 0.352
;
proc transpose data=have out=middle prefix=VAR  ;
  id momr ;
run;

data want ;
  set middle ;
  diff = var5 - var1;
run;
proc print;
run;
Obs    _NAME_      VAR1      VAR2      VAR3      VAR4      VAR5      diff

 1     std_res     5.324     4.694     5.122     5.763     6.116     0.792
 2     sta_res    -0.140    -0.153    -0.116    -0.029    -0.007     0.133
 3     _rsq        2.111     2.189     2.443     2.764     3.292     1.181
 4     id         -0.041    -0.053    -0.062    -0.058    -0.057    -0.016
 5     skewret     0.283     0.317     0.429     0.444     0.352     0.069
Ask a Question
Discussion stats
  • 2 replies
  • 80 views
  • 0 likes
  • 3 in conversation