show/hide this revision's text 3 add code formatting;

Hello,

Here is a solution for both questions with the use of arrays.

Regards

DATA result(KEEP=id min max);  
SET dataset;  
ARRAY dates date1-date10;  
ARRAY results result1-result10;  

id_min=1;  
id_max=1;  

DO i=2 TO 10;    
IF dates{i}>dates{id_maxdates{i}>dates{id_max} THEN id_max=i;    
    IF dates{i} < dates{id_min} THEN id_min=i;      
END;

first=results{id_min};
last=results{id_max};

/* Check if at least two valid values */  
nb_Not_Missing=N(OF date1-date10);  
IF nb_Not_Missing<=1 THEN last=.;  

RUN;
show/hide this revision's text 2 improved formatting

Hello,

Here is a solution for both questions with the use of arrays.

Regards

DATA result(KEEP=min result(KEEP=id min max);
SET dataset;
ARRAY dates date1-date10;
ARRAY results result1-result10;

id_min=1;
id_max=1;

DO i=2 TO 10;
IF dates{i}>dates{id_max} THEN id_max=i;
/*issue to write with this editor: please insert here same line as above remplacing ">" by "<" and "idmax" by "idmin" */
IF dates{i} < dates{id_min} THEN id_min=i;
END;

first=results{id_min}; last=results{id_max};

/* Check if at least two valid values */
nb_Not_Missing=N(OF date1-date10);
IF nb_Not_Missing<=1 THEN last=.;

RUN;

show/hide this revision's text 1

Hello,

Here is a solution for both questions with the use of arrays.

Regards

DATA result(KEEP=min max);
SET dataset;
ARRAY dates date1-date10;
ARRAY results result1-result10;

id_min=1;
id_max=1;

DO i=2 TO 10;
IF dates{i}>dates{id_max} THEN id_max=i;
/*issue to write with this editor: please insert here same line as above remplacing ">" by "<" and "idmax" by "idmin" */
END;

first=results{id_min}; last=results{id_max};

/* Check if at least two valid values */
nb_Not_Missing=N(OF date1-date10);
IF nb_Not_Missing<=1 THEN last=.;

RUN;