Help using Base SAS procedures

PROC Report: Making Several Columns be a single Row

Reply
Frequent Contributor
Posts: 76

PROC Report: Making Several Columns be a single Row

Hello Everyone,

 

I have a dataset with calculated outputs using SAS-callable SQL (one observation per a variable) and it is structured like this:

 

SAS Output from proc report:

 

Var 1

Var 2

Var 3

3165

73

309

 

And I would like it like this:

 

 

 

 

Var1

3165

 

Var2

73

 

Var3

309

 

 

 

I have tried using the across statement in proc report, but all it does is add a one underneath each column in the longitudinal graph. I also thought about using proc transpose, but I am not sure if it would work in this case, plus I would prefer to be able to use proc reports ability to rename columns (except in this case they would be rows). Here is my code:

 

proc report data = test nowd;
columns var1 var2 var3;

 

define var1 / style(COLUMN)={JUST=l CELLWIDTH=35}
                     style(HEADER)={JUST=l CELLWIDTH=35}
                      "Variable 1" order
;
define var2    / style(COLUMN)={JUST=l CELLWIDTH=35}
                     style(HEADER)={JUST=l CELLWIDTH=35}
                      "Variable 2" order
;

define var3    / style(COLUMN)={JUST=l CELLWIDTH=35}
                     style(HEADER)={JUST=l CELLWIDTH=35}
                      "Variable 3" order
;

run;

 

 

Thank you!

Valued Guide
Posts: 860

Re: PROC Report: Making Several Columns be a single Row

[ Edited ]
Posted in reply to daszlosek

Transpose will work:

 

data have;
input var1 var2 var3;
cards;
3165 73 309
;

proc transpose data=have out=want;var var:;

 

If the variables are numeric you do not need the var statement. 

Super User
Super User
Posts: 7,942

Re: PROC Report: Making Several Columns be a single Row

Posted in reply to daszlosek

Hi,

 

There is a whole raft of guidance and help on this topic, you are looking for reshaping data from wide to long in this case.  Here is one document:

http://www.ats.ucla.edu/stat/sas/modules/ltow_transpose.htm

 

But a search on here or the web will result in many pages on the topic to fit the many scenarios possible.

Ask a Question
Discussion stats
  • 2 replies
  • 233 views
  • 0 likes
  • 3 in conversation