Write and run SAS programs in your web browser

Proc Transpose gives me a stepped table

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Proc Transpose gives me a stepped table

I proc transposed this:

Capture3.PNG

proc sort data=ngr2 out=ngr1;
by no;
run;

proc transpose data=Ngr1 out=ngr;
	by no;
	id nigeria;
	var _2011 _2012 _2013 _2014 _2015 _2016;
run;

 

and got this:

Capture.PNG

 

but I want something like this

Capture2.PNG

 

Thanks in advance


Accepted Solutions
Solution
‎05-14-2016 11:56 PM
Grand Advisor
Posts: 17,360

Re: Proc Transpose gives me a stepped table

You don't need a BY statement, in fact a 'basic' proc transpose should get you much closer:

 

proc transpose data=have out=want;
run;

Add back portions of code until you get what you need with the minimal amount of code. You should end up with something similar to this:

 

proc transpose data=have out=want;
id var_name;
var _2011 _2012 _2013 _2014 _2015 _2016;
run;

View solution in original post


All Replies
Solution
‎05-14-2016 11:56 PM
Grand Advisor
Posts: 17,360

Re: Proc Transpose gives me a stepped table

You don't need a BY statement, in fact a 'basic' proc transpose should get you much closer:

 

proc transpose data=have out=want;
run;

Add back portions of code until you get what you need with the minimal amount of code. You should end up with something similar to this:

 

proc transpose data=have out=want;
id var_name;
var _2011 _2012 _2013 _2014 _2015 _2016;
run;
New Contributor
Posts: 3

Re: Proc Transpose gives me a stepped table

Thank you!
Respected Advisor
Posts: 4,608

Re: Proc Transpose gives me a stepped table

I assume that variable no is only there to set a column order in your transposed table. That's fine. But it shouldn't be involved in the transposition. Simply do:

 

proc transpose data=Ngr1 out=ngr name=Year;
	id Nigeria;
	var _2011 - _2016;
run;
PG
New Contributor
Posts: 3

Re: Proc Transpose gives me a stepped table

Thank you also for your help!
☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 252 views
  • 0 likes
  • 3 in conversation