DATA Step, Macro, Functions and more

Proc Transpose Help

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Proc Transpose Help

I have a dataset:

 

idnamedmvalue
101weightds50
101weightds55
101weightds54
101weightds49.8
101weightds53

 

i need to output:

iddmweight
101ds50
101ds55
101ds54
101ds49.8
101ds53

 

 

using proc transpose how can i do it?


Accepted Solutions
Solution
‎01-17-2017 07:49 AM
PROC Star
Posts: 307

Re: Proc Transpose Help

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?

View solution in original post


All Replies
Solution
‎01-17-2017 07:49 AM
PROC Star
Posts: 307

Re: Proc Transpose Help

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?

Occasional Contributor
Posts: 11

Re: Proc Transpose Help

Posted in reply to collinelliot

thanx that worked

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 152 views
  • 1 like
  • 2 in conversation