DATA Step, Macro, Functions and more

Using Array variable with AND

Reply
Frequent Contributor
Posts: 126

Using Array variable with AND

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[10] 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;

 end;

 

Thanks,

Brian

 

SAS Super FREQ
Posts: 8,740

Re: Using Array variable with AND

[ Edited ]

Hi:
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.

cynthia

Super User
Posts: 10,466

Re: Using Array variable with AND

[ Edited ]

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

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

shows one way to turn your dataset into a data step.

Frequent Contributor
Posts: 126

Re: Using Array variable with AND

ballardw,
Thanks for the link. I'll try using that macro tomorrow.

Cynthia,
The dx variables are character.
Super Contributor
Posts: 254

Re: Using Array variable with AND

[ Edited ]

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?

Frequent Contributor
Posts: 126

Re: Using Array variable with AND

datasp,
Yes, the macro variables are lists of diagnosis codes
Ask a Question
Discussion stats
  • 5 replies
  • 288 views
  • 0 likes
  • 4 in conversation