I have a large dataset in SAS that I need to change to wide from long.
Basically, the data is sorted with multiple observations for each property for about 10 different years with around 150 variables. I would like to make it so each variable is a different year and have one observation per property. Each variable is uniquely named and I want to keep the name in it.
What I have:
Property Year Var1 ... Var150
Prop 1 2010 100 ... ABC
Prop 1 2011 101 ... DEF
.
.
Prop 1 2017 138 ... XYZ
Prop2 ...
What I want:
Property Var1_2010 ... Var1_2017 ... Var150_2010 ... Var150_2017
Prop1 100 ... 138 ... ABC ... XYZ
Prop2 ...
I tried using Proc Transpose, but I cannot find a way to concatenate the year at the end of each original variable name.
I also tried:
proc sort data=hotels;
by propertyID year;
run;
proc transpose data=hotels out=hotels_wide;
by propertyID year;
var _all_;
run;
proc transpose data=hotels_wide delimiter=_ out=hotels_wide_full(drop=_name_);
by propertyID;
var col1;
id _name_ year;
run;
But the last block gave me an error telling me there are multiple occurrences of each variable for each propertyID. A shortcoming of this would also be losing the formats of each variable.