Transpose long to wide in SAS

后端 未结 3 584
别跟我提以往
别跟我提以往 2021-01-28 18:53

I have a very large data set (18 million observations) that I would like to transpose by subsetting based on one variable and creating 900 new variables out of those sub/ets. Ex

3条回答
  •  爱一瞬间的悲伤
    2021-01-28 19:01

    Transpose steps like this are easily done with the array statement. Example for your code would be something like:

    data new (keep = year var1-var3);
      set data;
      by year;
      array vars {3} var1-var3;
      retain var1-var3;
      if first.year then i=1;
      else i+1;
      vars{i} = faminc;
      if last.year then output;
    run;
    

    But I don't have SAS to double check this. Also see here.

    There are no good transpose procedures in PROC SQL.Too limited.

提交回复
热议问题