if first.patid then call missing(difference); if difference = . or difference <= 180 then ep = 0; ep + 1;
Here is the sample data:
PatID. FirstDayofService. LastDayofService. Difference Episode
| AB1 | 2015-10-31 | 2015-10-31 | . | 1 |
| AB1 | 2016-05-14 | 2016-05-14 | 196 | 2 |
| AB1 | 2017-12-13 | 2017-12-13 | 578 | 3 |
| AB1 | 2017-12-13 | 2017-12-13 | 0 | 1 |
| AB1 | 2017-12-13 | 2017-12-13 | 0 | 1 |
In this sample data, I am calculating the difference between first day of service and next first day of service. If the difference is 0 or < 180 days then I am trying to add the same episode. Else Episode will increase by 1. For the first three rows highlighted in green, its working correctly. For the next two rows, highlighted in orange, it's not working correctly as its incorrectly showing episode as 1. It should take the episode based on previous episode value. i.e. 3 if the difference is less than 180. In this case the correct response for last two rows in episode column should be 3.
Please help me out.
Thank you for your response. When I use the fix below, I am getting the correct logic but not the correct result:
Episode should show 1,2,3,3,3, Here it is starting at 0.
I tried changing the initial value of episode to 1,
rsubmit; data check1; set check; by FDS;/*First day of Service*/ if first.patid then do; difference = 0; episode = 1; end; if difference > 180 then episode +1; run; endrsubmit;
But even then its showing the same results.
If the difference is 0 or < 180 days then I am trying to add the same episode.
Right know your code does the opposite:
if difference = . or difference <= 180 then ep = 0;
A fix could be:
if first.patid then do;
difference = 0;
ep = 0;
end;
if difference > 180 then ep +1;
Thank you for your response. When I use the fix below, I am getting the correct logic but not the correct result:
Episode should show 1,2,3,3,3, Here it is starting at 0.
I tried changing the initial value of episode to 1,
rsubmit; data check1; set check; by FDS;/*First day of Service*/ if first.patid then do; difference = 0; episode = 1; end; if difference > 180 then episode +1; run; endrsubmit;
But even then its showing the same results.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.