Hello,
I have a very basic question regarding a table where I would like to change the order of rows and columns.
The problem is illustrated by the picture below. I have a SAS table in the upper format and would like to transform it to the format describes below.
I would be very glad if some could help me out.
Thanks a lot.
Peter
This is called a transpose.
Transposing data tutorials are here
Long to Wide:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/
https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/
Untested but this should be pretty close.
proc sort data=have;
by startYear variable;
run;
proc transpose data=have out=want;
by startYear;
ID variable;
value Estimate;
run;
@Tim_sas_ wrote:
Hello,
I have a very basic question regarding a table where I would like to change the order of rows and columns.
The problem is illustrated by the picture below. I have a SAS table in the upper format and would like to transform it to the format describes below.
I would be very glad if some could help me out.
Thanks a lot.
Peter
Try this:
proc sort data=myData; by startYear variable; run;
proc transpose data=myData out= want(drop=_name_);
by startYear;
var estimate;
id variable;
run;
(untested)
If all of the values of your Variable are acceptable as SAS variable names this should do it:
Assumes the data is sorted by startyear. If it isn't sorted then sort before the proc transpose.
Proc transpose data=have out=want; by startyear; id variable; var estimate; run;
This will however fail of any startyear value has multiple rows with the same value of Variable.
Could be a job for proc report using across, if you don't need a dataset, but a report.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.