☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-06-2024 04:54 AM
(1866 views)
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;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
how silly of me.
e
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you.