A problem with the interaction of the scan() and find() functions

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

A problem with the interaction of the scan() and find() functions

Hello,

I have string variable that contains various treatment notes, which may or may not include one or more drug names.  I also have a list of target drug names in the form of a string delimited by commas ','. The content of the treatment notes changes with each entry, while the drug name list is constant.  For each entry, I would like to count the number drugs from my list that show up in the treatment notes.

I am trying to accomplish this within a do-loop, which uses the scan() function to step through the entries in the drug list and then use the find() function to search for each drug in the treatment notes.  However, the scan() function doesn't seem to be passing the drug names to the find() function.

A typical string containing the treatment notes looks like this:

"Herceptin 2 mg/kg IV weekly x6 (2 cycles prior to restaging)"  (the "quotes" are not explicitly included in the string)

the variable containing the notes called tx_notes

nephrotox_chemo is supposed to contain the number of drugs from the list which show up in the treatment notes.

here is the essence of the do-loop:

do i = 1 to 9;

       chemo=scan("Bevacizumab,Irinotecan,Pemetrexed,Cetuximab,Cytarabine,Rituximab,Trastuzumab,Herceptin,Methorexate",i,',');

 

       if find(tx_notes,chemo, ' ',"i") > 0 then nephrotox_chemo +1;

end;

Unfortunately, the find() function will always return 0, even though at i=8, Herceptin is in both strings.

If I explicitly enter "Herceptin" as the second argument to the find() function (see below) then find() works as it should.

if find(tx_notes,"Herceptin", ' ',"i") > 0 then nephrotox_chemo +1;    *This works*

Clearly the drug names are not being passed to the find function, but I am at a loss as to why this is the case.  Any help would be appreciated.

I am running SAS 9.3 via Enterprise Guide 4.3 on Windows XP.

-Andrew


Accepted Solutions
Solution
‎03-12-2014 11:29 AM
Respected Advisor
Posts: 3,799

Re: A problem with the interaction of the scan() and find() functions

Add the T trim option in there with I for ignore case.  That should help.

View solution in original post


All Replies
Solution
‎03-12-2014 11:29 AM
Respected Advisor
Posts: 3,799

Re: A problem with the interaction of the scan() and find() functions

Add the T trim option in there with I for ignore case.  That should help.

Occasional Contributor
Posts: 6

Re: A problem with the interaction of the scan() and find() functions

Posted in reply to data_null__

That did it.  Thanks.

Also, for the sake of posterity, I should revise my original post.  The command I was attempting to use was actually:

if find(tx_notes,chemo,"i") > 0 then nephrotox_chemo +1; 


(note there is one fewer argument provided to find().  The whitespace delimiter argument was from previous attempts with the findw() function and lazy copy/pasting).


Thanks again

Occasional Contributor
Posts: 6

Re: A problem with the interaction of the scan() and find() functions

Could you please provide me the syntax that worked in your case. I have a similar issue with my code. Please review my notes below.

Occasional Contributor
Posts: 6

Re: A problem with the interaction of the scan() and find() functions

Posted in reply to data_null__

Could you please provide me the syntax for my above situation. I believe you suggested something that worked earlier for Andrew.

Note: My code is on the Mainframe (SAS).

Occasional Contributor
Posts: 6

Re: A problem with the interaction of the scan() and find() functions

Posted in reply to Raju_SAS_User

My colleague found the solution to the above issue.

STRIP Function is to be used instead of TRIM. STRIP function removes both leading and trailing blanks. While trim only removes trailing blanks.

So the Syntax used was

   F=INDEX(STRIP(STRENGTH),STRIP(ASTR));

OR

F=FIND(STRIP(STRENGTH),STRIP(ASTR));

Also, there was no need for using Arrays. I could loop the record using the DO LOOP as I originally planned.

Super User
Posts: 5,426

Re: A problem with the interaction of the scan() and find() functions

Actually, this seems like a SAS bug.

If you wish to use a modifier, it looks like you can't use a variable as a second argument.

So, report it SAS tech support...

Data never sleeps
Occasional Contributor
Posts: 6

Re: A problem with the interaction of the scan() and find() functions

thanks for the reply.  Per data_null_, adding the trim option fixed the problem, even when using variables as both the string and substring arguments.

Thanks!

Occasional Contributor
Posts: 6

Re: A problem with the interaction of the scan() and find() functions

Hello,

I read this post. I have a similar issue. Could you please review and let me know the proper syntax for this operation.

DATA PASS_STR FAIL_STR;

SET PREVDATA;                                  

MATCH='Y';                                            

ARRAY ASTR(*) _CHARACTER_;                            

CW=COUNTW(ACTIVE_ING,';');                     

DO C=1 TO CW BY 1 WHILE(MATCH='Y');                  

   ASTR=SCAN(ACTIVE_ING,C,';');

   F=INDEX(STRENGTH,TRIM(ASTR(C)));                   

   IF F=0 THEN MATCH='N'; 

PUT C CW F MATCH ASTR(C) STRENGTH;                    

END;                                                  

   IF MATCH='Y' THEN OUTPUT PASS_STR;                  

   IF MATCH='N' THEN OUTPUT FAIL_STR;                  

The result I get is the following. As you can see as soon as the program starts reading the second array component it fails to find the ASTR(2). 

1 4 15 Y   1.23      1.25MG;1.25MG;1.23MG;1.25MG        

2 4 0 N    1.25       1.25MG;1.25MG;1.23MG;1.25MG         

1 4 1 Y    1.875     1.875MG;1.875MG;1.875MG;1.875MG    

2 4 0 N    1.875     1.875MG;1.875MG;1.875MG;1.875MG    

1 4 1 Y     2.5        2.5MG;2.5MG;2.5MG;2.5MG              

2 4 0 N     2.5        2.5MG;2.5MG;2.5MG;2.5MG           

When I take the SCAN process outside of the above DO loop and run it in its own DO loop I am not able to populate beyond ASTR(2).  I get zero values for ASTR(3) and ASTR(4) values

DO C=1 TO CW BY 1;                            

ASTR(C)=SCAN(ACTIVE_STRENGTH,C,';');

END;                                          

Can you please review the situation above and assist.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 518 views
  • 0 likes
  • 4 in conversation