Covert wide to long in sas when all the variable has the suffix needed

谁都会走 提交于 2021-01-29 14:41:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!