BookmarkSubscribeRSS Feed
yotsuba88
Quartz | Level 8

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.

 

 

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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;

 

 

 

Tom
Super User Tom
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 717 views
  • 0 likes
  • 3 in conversation