- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear SAS community
I used this code to search a text field (procedure_name) but it yielded wrong data in all of the "pro_" fields. But the if I use .... where procedure_name contains xxx then the results make sense so I know this field has searchable text.
Could you please tell me what is wrong with my code using index function?
data procedure1; set procedure;
pro_icd=0; pro_pacer=0; pro_emb=0; pro_cabg=0; pro_pci=0; pro_valvesurg=0; pro_codeblue=0; pro_ett=0; pro_ablation=0; pro_cor_angio=0; pro_ccta=0; pro_ccs=0;
if index(lowcase(procedure_name), "defibrillator")=1 then pro_icd=1;
if index(lowcase(procedure_name), "pacemaker")=1 then pro_pacer=1;
if index(lowcase(procedure_name), "biopsy of heart")=1 then pro_emb=1;
if indexc(lowcase(procedure_name), "bypass coronary artery","cardiac bypass graft surgery","coronary artery bypass")=1 then pro_cabg=1;
if index(lowcase(procedure_name), "dilation of coronary artery")=1 then pro_pci=1;
if index(lowcase(procedure_name), "cardiac valve replacement")=1 then pro_valvesurg=1;
if index(lowcase(procedure_name), "cardiopulmonary resusitation")=1 then pro_codeblue=1;
if index(lowcase(procedure_name), "cardiovascular stress test")=1 then pro_ett=1;
if index(lowcase(procedure_name), "ablation")=1 and index(lowcase(procedure_name), "heart")=1 then pro_ablation=1;
if indexc(lowcase(procedure_name), "coronary angiography","coronary arteriography")=1 then pro_cor_angio=1;
if index(lowcase(procedure_name), "heart")=1 and indexc(lowcase(procedure_name), "catheterization")=1 then pro_cor_angio=1;
if indexc(lowcase(procedure_name), "computed tomographic angiography, heart, coronary arteries")=1 then pro_ccta=1;
if index(lowcase(procedure_name), "coronary calcium")=1 then pro_ccs=1;
keep empi procedure_name code pro_test:;
run;
Thanks so much in advance
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Do you have procedure_name data to show here? There might be multiple reasons the function is not giving the expected results.
Your current code assumes that the searched word comes first in the string in procedure_name variable without preceding spaces.
If this assumption is true then try adding STRIP() function to your existing code.
if index(lowcase(strip(procedure_name)), "defibrillator")=1 then pro_icd=1;
If the string doesn't start with the searched word you can use FIND function instead. It gives you 1 if true, and the condition works.
if find(lowcase(procedure_name), "defibrillator")=1 then pro_icd=1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Do you have procedure_name data to show here? There might be multiple reasons the function is not giving the expected results.
Your current code assumes that the searched word comes first in the string in procedure_name variable without preceding spaces.
If this assumption is true then try adding STRIP() function to your existing code.
if index(lowcase(strip(procedure_name)), "defibrillator")=1 then pro_icd=1;
If the string doesn't start with the searched word you can use FIND function instead. It gives you 1 if true, and the condition works.
if find(lowcase(procedure_name), "defibrillator")=1 then pro_icd=1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
this works! thanks so much
I should not have assume =1 because the text did not always start on the first position.
very much appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Index returns the position number if the text is found. So if the target text might not start on the first column of the searched text:
if index(lowcase(procedure_name), "defibrillator") ge 1 then pro_icd=1;
ge is greater than or equal.