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
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.