SAS and line pointers in a loop -


data test;     infile datalines;     input k1 k2 k3 k4 k5 k6 k7 k8 k9 k10;     array a(*) k1-k10;     i=1 10;         if a(i) eq . stop;         line=a(i);         input #line k1 k2 k3 k4 k5 k6 k7 k8 k9 k10;         output;     end;     stop;     datalines;         5 9 2 4 6 3 . . . .         29 57 32 9 2 29 2 0 23 1         83 34 28 1 43 3 24 2 6 2         0 84 62 75 3 52 65 1 5 2         0 2 12 45 92 3 60 24 6 2         47 24 87 2 52 36 1 17 3 1         90 93 2 1 40 20 75 2 5 14         78 27 27 2 4 1 12 21 4 2         21 40 3 21 3 19 3 2 4 2         84 2 5 3 13 6 23 98 1 2      ; run; 

i want read observations numbers in first row. expected result:

0  2  12 45 92 3  60 24 6  2 21 40 3  21 3  19 3  2  4  2 29 57 32 9  2  29 2  0  23 1 0  84 62 75 3  52 65 1  5  2 47 24 87 2  52 36 1  17 3  1 83 34 28 1  43 3  24 2  6  2 

the error after running code:

error: old line 3387 wanted sas @ line 3391.        use: infile n=x; , suitable value of x. rule:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 3391                47 24 87 2 52 36 1 17 3 1 k1=0 k2=2 k3=12 k4=45 k5=92 k6=3 k7=60 k8=24 k9=6 k10=2 i=2 line=2 _error_=1 _n_=1 

what "a suitable value of x" mean? should change in code?

you overwriting values in array second input statement. here read different variables not overwritten.

data test;     infile datalines n=100;     input h1 h2 h3 h4 h5 h6 h7 h8 h9 h10;     array h{*} h1-h10;     = 1 10;         line = h[i];         if line do;             input #line k1 k2 k3 k4 k5 k6 k7 k8 k9 k10;             output;         end;     end;     keep k:;     datalines;         5 9 2 4 6 3 . . . .         29 57 32 9 2 29 2 0 23 1         83 34 28 1 43 3 24 2 6 2         0 84 62 75 3 52 65 1 5 2         0 2 12 45 92 3 60 24 6 2         47 24 87 2 52 36 1 17 3 1         90 93 2 1 40 20 75 2 5 14         78 27 27 2 4 1 12 21 4 2         21 40 3 21 3 19 3 2 4 2         84 2 5 3 13 6 23 98 1 2      ; run; 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -