Transposing wide to long with an array in SAS

后端 未结 1 877
你的背包
你的背包 2021-01-27 02:08

I have a SAS dataset, with the following variables: ID, Var1_0, Var1_3, Var1_6, Var2_0, Var2_3, Var2_6, which can be read like this: Var1_0 is parameter 1 at time 0. For every s

相关标签:
1条回答
  • 2021-01-27 02:57

    Reeza gave you the answer in her comment. Here it is typed out.

    data long;
       set wide;
       array a[*] Var1_0 Var1_3 Var1_6 Var2_0 Var2_3 Var2_6;
       do i=1 to dim(a);
          outcome = a[i];
          var = vname(a[i]);
          time = input(scan(var,2,'_'),best.);
          /*Other stuff you want to do*/
          output;
       end;
    run;
    

    VNAME(array[sub]) gives you the variable name of the variable referenced by array[sub].

    scan(str,i,delim) gives you the ith word in str using the specified delimiter.

    0 讨论(0)
提交回复
热议问题