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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.