My goal is to extract all observations with an item_name that matches the value of the macro variable expense_type, from a dataset like the one below Right now, my solution is only extracting those observations that start with that word: observations like the one below, which include that word in a different position are not included I've been trying to debug to figure out what the current word is in the loop iteration, but I keep getting errors. put 'current_word: ' scan(item_name, n); isn't working. How can I even debug in this case? this is my code: /* find observations with item_codes corresponding to the specific expense type keyword user wants */
data item_docs_specific;
set item_docs;
%LET expense_type = "&expense_type"; /* loop through item_name variable to find observations that match with the expense type keyword use.r wanted */
do n=1 to countw(item_name);
put 'item_name:' item_name;
/* put 'current word #': n; */
/* put 'current_word: ' scan(item_name, n); */
/* put 'expense_type:' &expense_type; */
if count(lowcase(scan(item_name,n)), lowcase(&expense_type)) > 0;
output;
end; drop n; run;
... View more