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,
proc transpose data=have out=want;
id id;
var code1 code2;
run;
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
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 |
proc transpose data=have out=want;
id id;
var code1 code2;
run;
@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;
Perfect!
Thank you so much.
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.
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.