在SAS数据步骤中有条件地选择数据集

时间:2018-08-27 20:59:31

标签: macros do-loops

我想根据特定条件在2个数据集之间进行选择。我认为正确的结果要么进入了错误的状态,要么最终陷入了无限循环。我想在宏中完成所有这些操作,并在条件为真时退出循环。

%MACRO M;
%DO %UNTIL (ICU_LAST=FALSE);
    /* REMOVE ANY "LAST" RECORDS THAT ARE IN ICU AS THEY WILL NOT HAVE A LLOC ASSOCIATED WITH THEM */
    DATA LAST_TEST1;
        FALSE = 0;
        TRUE = 1;
        FORMAT SEEN 8.;
        RETAIN SEEN;
        RETAIN RECNO;
        IF SEEN=. THEN SEEN = FALSE;
        IF SEEN = FALSE THEN 
        DO;
            SET TESTTABLE_ENUMERATE END = LAST;
            SEEN = TRUE;
        END;
        ELSE
            SET RM_LAST_ICU END = LAST;
        IF LAST THEN
            ENDRECNO = 'LAST';
    RUN;

    /* IF THE LAST RECORD FOR EACH ACCOUNT IS AN ICU UNIT THEN DELETE IT AS THERE WILL BE NO ORDER OR ADMIT DATES ASSOCIATED WITH IT */
    DATA RM_LAST_ICU;
    FORMAT ICU_LAST 8.;
    IF ICU_LAST = . THEN ICU_LAST = FALSE;
    SET LAST_TEST1;
    IF LOCATIONNURSEUNITCODEDESC IN (&ICU_LIST.) AND ENDRECNO = 'LAST' THEN 
        DO;
            DELETE;
            ICU_LAST = TRUE;
        END;
    ELSE
        ICU_LAST = FALSE;
    RUN;

%END;
%MEND;
%M;

0 个答案:

没有答案