What you have to do is sort your data set to have the Z observation on the very first observation. Then read the dataset with a DATA step, and
RETAIN Zvalue ;
IF _N_=1 THEN Zvalue = value ;
The RETAIN instruction will ensure that the value is remembered for any further observation read.
If there are several values to remember, declare every variable in a single RETAIN, and create them in the IF _N_=1 statement. You can use ARRAYs to simplify syntax, working on week_1, week_2, etc.
Many thanks for your reply.
I am not sure to well understand. I have to create new variables for each week_i of my Z(last or first) row?
Here is the macro:
%Macro DUMMY_PERF_HEBDO (table=) ;
data &table.2 (drop=monthly_perf_week_1-monthly_perf_week_500);
set &table ;
array monthly_perf_week_[&_N_week] monthly_perf_week_1-monthly_perf_week_500;
array dummy_week_ dummy_week_1-dummy_week_500;
retain monthly_perf_week_1-monthly_perf_week_500 dummy_week_1-dummy_week_500 ;
/*ATTENTION aux 1 premières données week_n*/
do _i=5 to 500;
If (monthly_perf_week_(_i)=0 or monthly_perf_week_(_i)=.) then dummy_week_(_i)=.;
ELSE if BETA =0 then dummy_week_(_i)=.;
Else dummy_week_(_i)=(monthly_perf_week_(_i)-BETA*(monthly_perf_week_(_i)/* THE LAST OR FIRST ROW */ );