キューから値を返します。
カテゴリ: | 特殊 |
data one; input x @@; y=lag1(x); z=lag2(x); datalines; 1 2 3 4 5 6 ; proc print data=one; title 'LAG Output'; run;
/***************************************************************************/ /* This program generates up to three lagged values. By increasing the */ /* size of the array and the number of assignment statements that use */ /* the LAGn functions, you can generate as many lagged values as needed. */ /***************************************************************************/ /* Create starting data. */ data old; input start end; datalines; 1 1 1 2 1 3 1 4 1 5 1 6 1 7 2 1 2 2 3 1 3 2 3 3 3 4 3 5 ; data new(drop=i count); set old; by start; /* Create and assign values to three new variables. Use ENDLAG1- */ /* ENDLAG3 to store lagged values of END, from the most recent to the */ /* third preceding value. */ array x(*) endlag1-endlag3; endlag1=lag1(end); endlag2=lag2(end); endlag3=lag3(end); /* Reset COUNT at the start of each new BY-Group */ if first.start then count=1; /* On each iteration, set to missing array elements */ /* that have not yet received a lagged value for the */ /* current BY-Group. Increase count by 1. */ do i=count to dim(x); x(i)=.; end; count + 1; run; proc print; run;
data x; do x=1 to 10; output; end; run; /* Compute the moving average of the entire data set. */ data avg; retain s 0; set x; s=s+x; a=s/_n_; run; proc print; run;
data x; do x=1 to 10; output; end; run; %let n=5; data avg (drop=s); retain s; set x; s=sum (s, x, -lag&n(x)) ; a=s / min(_n_, &n); run; proc print; run;
data x; do x=1 to 10; output; end; run; data ds1; do patient='A','B','C'; do month=1 to 7; num=int(ranuni(0)*10); output; end; end; run; proc sort; by patient; %let n = 4; data ds2; set ds1; by patient; retain num_sum 0; if first.patient then do; count=0; num_sum=0; end; count+1; last&n=lag&n(num); if count gt &n then num_sum=sum(num_sum, num, -last&n); else num_sum=sum(num_sum, num); if count ge &n then mov_aver=num_sum/&n; else mov_aver=.; run; proc print; run;
data _null_; put 'Fibonacci Sequence'; n=1; f=1; put n= f=; do n=2 to 10; f=sum(f, lag(f)); put n= f=; end; run;
Fibonacci Sequence n=1 f=1 n=2 f=1 n=3 f=2 n=4 f=3 n=5 f=5 n=6 f=8 n=7 f=13 n=8 f=21 n=9 f=34 n=10 f=55