Good morning folks!
I'm stumped and need your help.
Basic premise - we are playing with various scenarios in our data, and one
of them is to adjust datasets based on critical values.
The logic flow is to take the original dataset (which is divided into
segment groupings), generate the statistic of interest by segment, and
compare it to the chosen critical values for that segment.
If the calculated statistic is smaller than the critical value for a
segment, send the data out to a 'completed' dataset (ITSDONE).
If the calculated statistic is larger than the critical value for a
segment, delete the largest value in the dataset, and repeat until the critical value test is
satisfied (NOTDONE).
Unfortunately, I can't seem to figure out how to stop the do loop when
the critical value test is satisfied (when NOTDONE is empty).
The particular combination we are looking at right now requires 751
iterations for all segments to meet the test criteria.
...until we change something (which we immediately will).
I need to be able to do this without 'knowing' anything but the critical value and statistic.
Thanks so much for your help!
Wendy T.
Dataset START already contains the critical value (K_CRIT), and is sorted
by descending values of the variable ANGLE_K by SEGMENT.
Dataset STACKER (to receive dataset ITSDONE) already exists, and contains
one line with null values.
DATA LOOP ; SET START ;
PROC MEANS NOPRINT N DATA=LOOP ;
BY SEGMENT ;
VAR ANGLE_K ;
OUTPUT OUT=ORIG1 (DROP= _TYPE_ _FREQ_) N=ORIGINAL_N ; RUN ;
RUN ;
%MACRO CUTTOPVALUE ;
%DO I=1 %TO 751 ;
PROC MEANS NOPRINT DATA=LOOP ;
BY SEGMENT ;
VAR ANGLE_K ;
OUTPUT OUT=MEDIANS (DROP=_TYPE_) MEDIAN=MEDIAN ;
RUN ;
PROC SQL NOPRINT ;
CREATE TABLE CHECKER
AS SELECT LOOP.*, MEDIANS.MEDIAN, MEDIANS._FREQ_
FROM LOOP, MEDIANS
WHERE LOOP.SEGMENT=MEDIANS.SEGMENT ;
QUIT ;
DATA ITSDONE NOTDONE (DROP=MEDIAN _FREQ_) ; SET CHECKER ;
IF MEDIAN LE K_CRIT THEN OUTPUT ITSDONE ;
ELSE OUTPUT NOTDONE ;
RUN ;
DATA STACKER ; SET ITSDONE STACKER ;
IF SEGMENT = '' THEN DELETE ;
PROC SORT ; BY SEGMENT ; RUN ;
DATA LOOP ; SET NOTDONE ;
IF _N_ = 1 THEN DELETE ;
RUN ;
%END ;
%MEND CUTTOPVALUE ;
%CUTTOPVALUE ;
DATA FINISHED ; MERGE STACKER ORIG1 ; BY SEGMENT ; RUN ;