07-14-2016 03:09 PM
I'm using the code below to find is a patient who had an appendectomy also had a diagnosis of appendicitis within 30 days of the procedure. The code below doesn't seem to be working as expected. It is correctly flagging those with a diagnosis but not the 30-day AND part. Can anyone spot what's wrong?
array dx DX1 - DX10;
appdx_flag = 0;
chronic_flag = 0;
do i = 1 to 10;
if (left(trim(substr(dx[i],1,5))) in (&AppICD9Codes4)) and (ENC_DATE - DxWindow) <= 30 then
appdx_flag = 1;
07-14-2016 03:30 PM - edited 07-14-2016 03:30 PM
I'm curious about the DX1-DX10 variables are they character or numeric? generally, you don't use substr on a numeric variable. So I'm sort of surprised that your left(trim(substr isn't giving your automatic conversion messages in the log:
NOTE: Numeric values have been converted to character values at the places given by: (Line) : (Column).
NOTE: Character values have been converted to numeric values at the places given by: (Line) : (Column).
Aside from any issues of your date values in the IF, problems with the substr function could cause the IF not to work correctly.
07-14-2016 03:36 PM - edited 07-14-2016 03:38 PM
You should provide some example data. You don't show what types of values ENC_DATE and DxWindow are or what the values look like. Some of the more common questions relate to date values and if your variables are not actually date values then the subtraction would likely be incorrect.
So provide some example data, best in the form of a datastep so we can test code. This link
shows one way to turn your dataset into a data step.
07-14-2016 03:38 PM - edited 07-14-2016 03:39 PM
If you give two or three records(even fictious), then it will easy to visualize the problem. You use IN function with a macro variable. Is it a list?