03-12-2014 11:12 AM
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;
if find(tx_notes,chemo, ' ',"i") > 0 then nephrotox_chemo +1;
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.
03-12-2014 11:46 AM
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).
04-04-2015 09:14 PM
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.
04-04-2015 09:15 PM
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).
04-06-2015 07:12 AM
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
Also, there was no need for using Arrays. I could loop the record using the DO LOOP as I originally planned.
03-12-2014 11:41 AM
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...
03-12-2014 11:50 AM
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.
03-31-2015 03:08 PM
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;
ARRAY ASTR(*) _CHARACTER_;
DO C=1 TO CW BY 1 WHILE(MATCH='Y');
IF F=0 THEN MATCH='N';
PUT C CW F MATCH ASTR(C) STRENGTH;
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;
Can you please review the situation above and assist.
Need further help from the community? Please ask a new question.