如何在SAS中转置多列数据

How to transpose data with many columns in SAS

嗨,我是 SAS 的新手,我遇到了一个问题。我有包含 337 行和 64 列的数据。 它看起来像这样: enter image description here 我需要这样做: enter image description here

我试过使用proc转置,但是我觉得。 请帮忙

您将需要 TRANSPOSE BY DATE 然后 SORT by country date,我假设国家来自 label 原始变量.

示例: 3 个日期和 5 个变量,可轻松更改以获取更大的数据。

data total_returns(label='Example data');
  do date = '01jan2020'd to '03jan2020'd;
    array RI RI_1-RI_5;
    do over ri;
      demo_value + 1;
      RI = demo_value;
    end;
    output;
  end;
  label
    RI_1 = 'MSCI Country Biff blah blah blah'
    RI_2 = 'MSCI Country Bam blah blah blah'
    RI_3 = 'MSCI Country Boom blah blah blah'
    RI_4 = 'MSCI Country Zwok blah blah blah'
    RI_5 = 'MSCI Country Pow blah blah blah'
  ;
  format date yymmdd10.;
  drop demo_value;
run;

proc transpose 
  data=total_returns 
  out=stage1 ( 
    drop=_name_ 
    rename= ( _label_=Country  
              col1 = RI
            ) 
  )
;
  by date;
  var RI_1-RI_5;
  label country = ' ';
run;

proc sort data=stage1 out=want;
  by country date;
run;

proc print label data=total_returns;
  title "Original, across/array layout";
proc print data=want;
  title "Transposed and Sorted, categorical/vector layout";
run;

输出: