Hi, I recently got help figuring out how to use the"Preceding" function which worked well, Hurray!
The intent was to create a value called Day Diff subtracting a precedingdischarge date with a subsequent admit date and flag the following admit/discharge with a1 if the following admit date was within 30 days of the preceding discharge, else 0. That field iscalled “30DyReAdFLG”
I now need to reverse the process that I developed and use the"Following" function.
I still need to create the Day Diff value but using the “Following” function,and flag the preceding discharge date when the following admit date is within30 days, else 0.
It may seem like the same thing but actually is not, it has to do with which record gets flagged, the preceeding admit/discharge or the following admit/discharge record.
I have it almost working with the exception that when I am creating the valuecalled “30DyReAdFLG” which is the difference between a preceeding discharge dateand a subsequent admit date in days, and although it is populating correctly, it ispopulating with a negative(-) number.
The negative number causes all records to be flagged as 1
I have tried a few different permutationsbut cannot get rid of the negatives. Maybe someone with more experience canspot the problem.
Here is my “Preceding” script, and my “Following” script as well as some current output for the following script illustrating the (-)'s for better understanding. Any support would be appreciated, thank you.
CREATE TABLEar_asrh_dm_etl_beacon.Flg_ReAdAlgo1a4 AS
(SELECT AdmitClaim_id2,AdmitMem_id2, ADte AS admit, DDte AS discharge,
MAX(DDte) over (partition BY AdmitMem_id2 ORDER BY AdmitMem_id2,ADte
ROWS between 1 preceding and 1 preceding) AS “Prev. Disch.”,
ADte - MAX(DDte) over (partition by AdmitMem_id2 ORDER BY AdmitMem_id2,ADte
ROWS between 1 preceding and 1 preceding ) AS “Day Diff”,
CASE WHEN
ADte - MAX(DDte) over (partition BY AdmitMem_id2 ORDER BY AdmitMem_id2,ADte
ROWS between 1 preceding and 1 preceding ) <= 30
THEN 1 ELSE 0 END AS"30DyReAdFLG", AdmitPatStat_dl2, AdmitPatStat_id2,
AdmitProvRend_id2,AdmitProvRend_LastNamed2
FROM ar_asrh_dm_etl_beacon.Flg_ReAdAlgo1a3
GROUP BY AdmitMem_id2, ADte, AdmitClaim_id2, DDte, AdmitPatStat_dl2,AdmitPatStat_id2, AdmitProvRend_id2,AdmitProvRend_LastNamed2)
WITH DATA;
CREATE TABLEar_asrh_dm_etl_beacon.Flg_ReAdAlgo1a5 AS
(SELECT AdmitClaim_id2,AdmitMem_id2, ADte AS admit, DDte AS discharge,
MAX(ADte) over (partition BY AdmitMem_id2 ORDER BY AdmitMem_id2,DDte
ROWS between 1 following and 1 following) AS “SubsequentAdmit”,
DDte - MAX(ADte) over (partition by AdmitMem_id2 ORDER BY AdmitMem_id2,DDte
ROWS between 1 following and 1 following ) AS “Day Diff”,
CASE WHEN
DDte - MAX(ADte) over (partition BY AdmitMem_id2 ORDER BY AdmitMem_id2,DDte
ROWS between 1 following and 1 following ) <= 30
THEN 1 ELSE 0 END AS"30DyReAdFLG", AdmitPatStat_dl2, AdmitPatStat_id2,
AdmitProvRend_id2,AdmitProvRend_LastNamed2
FROM ar_asrh_dm_etl_beacon.Flg_ReAdAlgo1a3
GROUP BY AdmitMem_id2, ADte, AdmitClaim_id2, DDte, AdmitPatStat_dl2,AdmitPatStat_id2, AdmitProvRend_id2, AdmitProvRend_LastNamed2)
WITH DATA;
I used the wrong example so this is edited now.
AdmitClaim_id2 AdmitMem_id2 admit discharge SubsequentAdmit Day Diff 30DyReAdFLG
1005821 3057 1/24/2010 2/4/2010 2/25/2010 -21 1
2304418 3057 2/25/2010 3/5/2010 5/5/2010 -61 1
3398955 3057 5/5/2010 5/11/2010 6/18/2010 -38 1
5117714 3057 6/18/2010 6/29/2010 7/17/2010 -18 1
5812207 3057 7/17/2010 7/30/2010 8/18/2010 -19 1
6092480 3057 8/18/2010 8/24/2010 9/4/2010 -11 1
7161403 3057 9/4/2010 9/22/2010 9/24/2010 -2 1
7162225 3057 9/24/2010 9/30/2010 10/13/2010 -13 1
7450820 3057 10/13/2010 10/14/2010 10/15/2010 -1 1
7503170 3057 10/15/2010 10/16/2010 0
Message was edited by: wpoling_953