proc transpose by numerical variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

proc transpose by numerical variable

What do I need to add in this code to have the HtFt values be organized based on the year? The code I have now just puts the variables in columns, but not in the correct one by year. How do I specify this?

 

data work.Trees;
infile datalines delimiter = ',';
input Type :$6.
Year :4.
HtFt :2.
;
datalines;
Aspen,2009,15
Aspen,2010,16
Maple,2010,6
Maple,2011,8
Maple,2012,10
Spruce,2009,22
Spruce,2010,23
Spruce,2011,24
Spruce,2012,25
;

proc transpose
data = work.Trees
out = work.TreesWide;
by Type;
var HtFt;

run;


Accepted Solutions
Solution
‎11-13-2017 09:29 PM
Esteemed Advisor
Posts: 5,474

Re: proc transpose by numerical variable

Add the statement :

 

ID year;

PG

View solution in original post


All Replies
Solution
‎11-13-2017 09:29 PM
Esteemed Advisor
Posts: 5,474

Re: proc transpose by numerical variable

Add the statement :

 

ID year;

PG
Occasional Contributor
Posts: 11

Re: proc transpose by numerical variable

Yes, that was all it needed I guess. Thank you!

Super User
Posts: 23,235

Re: proc transpose by numerical variable

[ Edited ]

The code I have now just puts the variables in columns, but not in the correct one by year.

 

Are you sure about that?

 

You can the ID with PREFIX and/or IDLABEL options but if they're in the wrong place this won't fix that. 

 


HSM9 wrote:

What do I need to add in this code to have the HtFt values be organized based on the year? The code I have now just puts the variables in columns, but not in the correct one by year. How do I specify this?

 

data work.Trees;
infile datalines delimiter = ',';
input Type :$6.
Year :4.
HtFt :2.
;
datalines;
Aspen,2009,15
Aspen,2010,16
Maple,2010,6
Maple,2011,8
Maple,2012,10
Spruce,2009,22
Spruce,2010,23
Spruce,2011,24
Spruce,2012,25
;

proc transpose
data = work.Trees
out = work.TreesWide;
by Type;
var HtFt;

run;


 

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 135 views
  • 0 likes
  • 3 in conversation