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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.