Resources

Using the FLATDATA Statement

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: panex07.sas
 Description: Example program from SAS/ETS User's Guide,
              The PANEL Procedure
       Title: Using the FLATDATA Statement
     Product: SAS/ETS Software
        Keys: panel data
        PROC: PANEL
       Notes:

--------------------------------------------------------------*/

data flattest;
   seed = 111323;
   do i = 1 to 20;
      X_1 =   rannor(seed);
      X_2 =   rannor(seed);
      X_3 =   rannor(seed);
      X_4 =   rannor(seed);
      X_5 =   rannor(seed);
      X_6 =   rannor(seed);
      Y_1 =   i +  rannor(seed) + X_1 * 2;
      Y_2 =   i +  rannor(seed) + X_2 * 2;
      Y_3 =   i +  rannor(seed) + X_3 * 2;
      Y_4 =   i +  rannor(seed) + X_4 * 2;
      Y_5 =   i +  rannor(seed) + X_5 * 2;
      Y_6 =   i +  rannor(seed) + X_6 * 2;
      cs = cat("CS",i);
      num = rannor(seed);
      output;
   end;
run;


proc print data=flattest(obs=5);
   var i cs num X_1 X_2 X_3 X_4 X_5 X_6 Y_1 Y_2 Y_3 Y_4 Y_5 Y_6;
run;

proc panel data=flattest;
   flatdata indid=i tsname="t" base=(X Y)
            keep=( cs num seed )  / out=flat_out;
   id i t;
   model y = x / fixone noint;
run;

proc print data=flat_out(obs=6);
   var i t X Y cs num;
run;

data wide;
   set flat_out;
   by i;
   keep i num cs X_1-X_6 Y_1-Y_6;
   retain X_1-X_6 Y_1-Y_6;
   array ax(1:6) X_1-X_6;
   array ay(1:6) Y_1-Y_6;
   if first.i then do;
      do j = 1 to 6;
         ax(j) = 0;
         ay(j) = 0;
      end;
   end;
   ax(t) = X;
   ay(t) = Y;
   if last.i then output;
run;

proc print data=wide(obs=5);
   var i cs num X_1 X_2 X_3 X_4 X_5 X_6 Y_1 Y_2 Y_3 Y_4 Y_5 Y_6;
run;