hello.
I am using PROC TRANSPOSE to transpose three variables in a dataset, using ID as the BY variable. Data and syntax is included. However, I would like to keep two other variables: age and gender, so that my final file looks like the table below. I know how to do it with a different method, but at times it would be much more efficient if I could use PROC TRANSPOSE. Any suggestion?
id | _NAME_ | COL1 | gender | age |
1 | v1 | 3 | M | 20 |
1 | v2 | 4 | M | 20 |
1 | v3 | 3 | M | 20 |
2 | v1 | 4 | F | 22 |
2 | v2 | 3 | F | 22 |
2 | v3 | 2 | F | 22 |
3 | v1 | 5 | M | 34 |
3 | v2 | 1 | M | 34 |
3 | v3 | 5 | M | 34 |
data have;
input id age gender$ v1 v2 v3;
cards;
1 20 M 3 4 3
2 22 F 4 3 2
3 34 M 5 1 5
;
proc print;
proc transpose data=have out=want;
var v1 v2 v3;
by id;
proc print;
how silly of me.
e
Hi can have the following:
data have;
input id age gender$ v1 v2 v3;
cards;
1 20 M 3 4 3
2 22 F 4 3 2
3 34 M 5 1 5
;
proc print;
proc transpose data=have out=want;
var v1 v2 v3;
by id gender age;
proc print;
Read more about Proc transpose here:
thank you.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.