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!
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.
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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.