DATA Step, Macro, Functions and more

Transposing table

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 92
Accepted Solution

Transposing table

Hi there,

 

I tried to transpose a table, see below example:

 

ID Age1 Age1
A 10 20
C 30 40
D 50 60
E 70 80

 

I want:

AGE A C D E
Age1 10 30 50 70
Ag2 20 40 60 80
         

 

Any help will be very appreciated.

 

Thanks,


Accepted Solutions
Solution
‎12-18-2017 06:16 PM
PROC Star
Posts: 1,357

Re: Transposing table

proc transpose data=have out=want;
id id;
var code1 code2;
run;

View solution in original post


All Replies
PROC Star
Posts: 1,357

Re: Transposing table


data have;
input ID $ Age1 Age2;
datalines;
A 10 20
C 30 40
D 50 60
E 70 80
;

proc transpose data=have out=want;
id id ;
run;

 

You could have tried yourself. it's easy copy paste

Frequent Contributor
Posts: 92

Re: Transposing table

Posted in reply to novinosrin

Thank you!

 

I wonder if the variable Age1 and Age1 are characters, then the code is not working.

This is the other example:

 

ID code1 code2
A x h
C t j
D f b
E t h

 

I want:

CODE A C D E
code1 x t f t
code2 h j b h
Solution
‎12-18-2017 06:16 PM
PROC Star
Posts: 1,357

Re: Transposing table

proc transpose data=have out=want;
id id;
var code1 code2;
run;

Contributor
Posts: 39

Re: Transposing table

@ursula you can try the below,

 

data have;
input ID $ Age1 Age2;
datalines;
A 10 20
C 30 40
D 50 60
E 70 80
;
run;

proc transpose data=have;
var age:;
ID ID;
run;

Frequent Contributor
Posts: 92

Re: Transposing table

Posted in reply to soham_sas

Perfect! 

Thank you so much.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 204 views
  • 1 like
  • 3 in conversation