I have a dataset:
id | name | dm | value |
101 | weight | ds | 50 |
101 | weight | ds | 55 |
101 | weight | ds | 54 |
101 | weight | ds | 49.8 |
101 | weight | ds | 53 |
i need to output:
id | dm | weight |
101 | ds | 50 |
101 | ds | 55 |
101 | ds | 54 |
101 | ds | 49.8 |
101 | ds | 53 |
using proc transpose how can i do it?
The following seems to work:
data have;
input id name $ dm $ value;
datalines;
101 weight ds 50
101 weight ds 55
101 weight ds 54
101 weight ds 49.8
101 weight ds 53
;
proc sort data = have;
by id dm value;
run;
proc transpose data = have out = want;
by id dm value;
var value;
id name;
run;
But why? Why not just rename "value" to "weight" and drop "name" if you really need that specific structure?
The following seems to work:
data have;
input id name $ dm $ value;
datalines;
101 weight ds 50
101 weight ds 55
101 weight ds 54
101 weight ds 49.8
101 weight ds 53
;
proc sort data = have;
by id dm value;
run;
proc transpose data = have out = want;
by id dm value;
var value;
id name;
run;
But why? Why not just rename "value" to "weight" and drop "name" if you really need that specific structure?
thanx that worked
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.