问题
I want the first wide dataset to be as the second long datafile, I have thought about using array, but considering I have 100 variables (the example only have 2), do I need 100 arrays?
Could you let me know how to do?
回答1:
Use a double transpose. First transpose to a tall structure. Then split the name into the basename and time. Then transpose again. Here is untested code since no example data was provided (only photographs).
proc transpose data=have out=tall ;
by id;
var _numeric_;
run;
data fixed ;
set tall ;
time = scan(_name_,-1,'_');
_name_ = substr(_name_,1,length(_name_)-length(time)-1);
run;
proc sort data=fixed ;
by id time;
run;
proc transpose data=fixed out=want ;
by id time ;
id _name_;
var col1;
run;
来源:https://stackoverflow.com/questions/63963106/covert-wide-to-long-in-sas-when-all-the-variable-has-the-suffix-needed