BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DanielQuay
Quartz | Level 8

I am working with data trying to identify opioid useage.

 

data want;

set have;

IF INDEX(UPCASE(var1), "METHADONE")>0 or INDEX(UPCASE(var2), "METHADONE")>0 or
INDEX(UPCASE(var3), "METHADONE")>0 or INDEX(UPCASE(var4), "METHADONE")>0 or
INDEX(UPCASE(var5), "METHADONE")>0 or INDEX(UPCASE(var6), "METHADONE")>0 

THEN OPI_3=1;

run;

 

This code works for 14 of the 16 substances I am looking for.

But when I am looking for OPANA and CODIENE it is popping up with:

 

ERROR ##-###: The INDEX function call has too many arguments.

 

I think this may be something about how the data is formatted but I haven't had to use INDEX before.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Show the code that doesn't work. Showing working code doesn't help us isolate the issue, you likely forgot a quote, comma or bracket so pay attention to exactly where the error is indicated, SAS provides the line and column number for you to find it easily.

View solution in original post

6 REPLIES 6
Reeza
Super User
Show the code that doesn't work. Showing working code doesn't help us isolate the issue, you likely forgot a quote, comma or bracket so pay attention to exactly where the error is indicated, SAS provides the line and column number for you to find it easily.
DanielQuay
Quartz | Level 8

IF INDEX(UPCASE(var1), "OPANA" >0 or INDEX(UPCASE(var2), "OPANA")>0 or
INDEX(UPCASE(var3), "OPANA")>0 or INDEX(UPCASE(var4), "OPANA")>0 or
INDEX(UPCASE(var5), "OPANA")>0 or INDEX(UPCASE(var6), "OPANA")>0
THEN OPI_6=1;

 

IF INDEX(UPCASE(var1), "CODEINE" >0 or INDEX(UPCASE(var2), "CODEINE")>0 or
INDEX(UPCASE(var3), "CODEINE")>0 or INDEX(UPCASE(var4), "CODEINE")>0 or
INDEX(UPCASE(var5), "CODEINE")>0 or INDEX(UPCASE(var6), "CODEINE")>0
THEN OPI_16=1;

PaigeMiller
Diamond | Level 26

@DanielQuay wrote:

IF INDEX(UPCASE(var1), "OPANA" >0 or INDEX(UPCASE(var2), "OPANA")>0 or
INDEX(UPCASE(var3), "OPANA")>0 or INDEX(UPCASE(var4), "OPANA")>0 or
INDEX(UPCASE(var5), "OPANA")>0 or INDEX(UPCASE(var6), "OPANA")>0
THEN OPI_6=1;

 

IF INDEX(UPCASE(var1), "CODEINE" >0 or INDEX(UPCASE(var2), "CODEINE")>0 or
INDEX(UPCASE(var3), "CODEINE")>0 or INDEX(UPCASE(var4), "CODEINE")>0 or
INDEX(UPCASE(var5), "CODEINE")>0 or INDEX(UPCASE(var6), "CODEINE")>0
THEN OPI_16=1;


We also need to see the LOG, as I described above.

--
Paige Miller
PaigeMiller
Diamond | Level 26

Show us the log for this DATA step. We need to see everything in the log, code, NOTEs, WARNINGs, and ERRORs.

 

You need to preserve the formatting of the log by copying it as text and pasting it into the window that appears when you click on the </> icon. DO NOT SKIP THIS STEP!

--
Paige Miller
ballardw
Super User

If you are going to do such code frequently I suggest that you go ahead and make the case standard, either all lower or all upper so you can eliminate multiple Upcase(SSSS) the make code more readable.

 

And there are nicer ways to search for the same value among a bunch of variables:

data want;
   set have;
   array v Var1-var6;
   /* assumes all of the variables have been
UPCASED prior
*/ opi3 = ( whichc('METHADONE', of v(*))>0); run;

 

The WHICHC, and numeric WHICHN functions return the position number that the first parameter, in this case the word METHADONE appears in a list of variables, using an array for short hand instead of listing var1, var2, var3, var4,var5, var6. If a value match is found the function will return the position in that list, i.e. 3 would mean that VAR3 matched, or zero otherwise. The surrounding ( >0) means the variable is  assigned a comparison true/false result which is 1/0 numeric by default with SAS.

 

Fewer parentheses, fewer quotes, fewer commas and fewer OR mean that you are much less likely to miss one of them.

Reeza
Super User
data want;
   set have;

   array v Var1-var6;

*make this big enough to hold all values;
length str $500.;
str = upcase(catx('-', of v(*)));

   opi3 = index(str, 'METHADONE')>0;
   opi6 = index(str, 'OPANA')>0;
   opi16 = index(str, 'CODIENE')>0;


run;

Also, if you have DINs there's drug listing DBs that you can use to link your drugs and they're categorized by categories, one of which is opioids. We're currently building out our PDMP so we're using the DB as it's constantly updated in our process.

 

The approach above concatenates all the values into one string, separated by a hypen (-), and searches that string. Then you need a single line of code to search that new string and create your flags. You COULD design a loop that goes over your diagnosis to make this  more efficient if you have a ton of diagnosis.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1907 views
  • 2 likes
  • 4 in conversation