Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created December 19, 2018 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd to your computer and use it in GitHub Desktop.
Save statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd to your computer and use it in GitHub Desktop.
SAS - Wide to Extra Wide format - Double Transpose
/*This program shows an example of going from a wide format to an extra wide format.
Original question:
https://communities.sas.com/t5/SAS-Programming/Row-to-variable/m-p/522615/
*/
*Create sample data;
data have;
informat Case Variable $15.;
input Case $ Variable $ Y112 Y113 Y114;
cards;
Basic Temperature 20 23 25
Basic Speed 130 120 80
Serious Temperature 19 21 22
Serious Speed 140 110 90
;;;;
run;
*sort to transpose;
proc sort data=have;
by case variable;
*create long data set;
proc transpose data=have out=long1;
by case variable;
var Y112-Y114;
run;
*add in index to go to wide;
data long2;
set long1;
by case variable;
if first.variable then counter=1;
else counter+1;
run;
*go to wide format;
proc transpose data=long2 out=wide1;
by case;
id variable counter;
idlabel variable;
var col1;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment