Hey guys, i have a dataset where the observations are grouped by an ID (idgem) and each grout has observations for several years (jahr) ba halv month steps (jan1 - dec2) looks like this: i wrote an array to find the local maximum (precipitaion data) in comparing each variable with the following and the previous variable. the dec2 value is compared with the jan1 value of the following (by copying the column) year and jan1 is compared with dec2 of the previous year (by the lag function). now i have the problem with the first an the last year within a group (idgem). how do i tell SAS to compare dec2 of the last year just to dec1 of the same year and ignore jan1 of the following year. i tried with an if last.jahr then option, but it doesn't work. my code looks like this (the corresponding part is marked green at the end of it): data test4;
set mani;
array local [24]; /* kreiert eine neue Datenmatrix mit den Überschriften local1-local24, ohne Werte, Variablen wird ein Indice zugewiesen in [] */
do _n_ = 1 to 24;
local[_n_] = "" ;
end;
array maxi [24] jan1 jan2 feb1 feb2 mar1 mar2 apr1 apr2 may1 may2 jun1 jun2 /* definiert quasi die Variablen des 'Quell-arrays' hier: maxi mit den Quelldaten */
jul1 jul2 aug1 aug2 sep1 sep2 oct1 oct2 nov1 nov2 dec1 dec2;
do _n_ = 2 to 23;
if (maxi [_n_-1] < maxi [_n_]) and (maxi [_n_]> maxi [_n_+1]) then local [_n_] = maxi [_n_];
if maxi [_n_] = maxi [_n_-1] then local [_n_] = maxi [_n_];
if maxi [_n_] = maxi [_n_+1] then local [_n_] = maxi [_n_];
end;
do _n_ = 1; /* lag Funktion vergleicht mit dem Wert dec2 der vorhergehenden Observation */
if (maxi [_n_] > maxi [_n_+1]) and (maxi [_n_] > lag(dec2)) then local [_n_] = maxi [_n_];
if (maxi [_n_] = maxi [_n_+1]) and (maxi [_n_] = lag(dec2)) then local [_n_] = maxi [_n_];
end;
do _n_= 24;
if (maxi [_n_] > maxi [_n_-1]) and (maxi [_n_] > jan1follow) then local [_n_] = maxi [_n_];
if (maxi [_n_] = maxi [_n_-1]) and (maxi [_n_] = jan1follow) then local [_n_] = maxi [_n_];
end;
if (last.jahr) then do _n_ = 24;
if (maxi [_n_] > maxi [_n_-1]) then local [_n_] = maxi [_n_];
if (maxi [_n_] = maxi [_n_-1]) then local [_n_] = maxi [_n_];
end;
if first.jahr then do _n_ = 1;
if (maxi [_n_] > maxi [_n_+1]) then local [_n_] = maxi [_n_];
if (maxi [_n_] = maxi [_n_+1]) then local [_n_] = maxi [_n_];
end;
run; there is no error message but also no difference in the results! any ideas? greets, Sandra
... View more