You can make use of arrays for this type of work, see sample code below. For each obs loop through all values and check for the text, if text is found get variable name, compare to a list and add if not found. * test data ; data have; infile cards dlm=","; input subject : $12. F1 : $12. F2 : $12. F3 : $12. F4 : $12. F5 : $12. F6 : $12. ; cards; 10002, 4, 7, 9, 9, 10, 9 10001, 0, 3, 4, Total (JD), 7, Total (PP) 10006, 8, 8, 8, 0, 9, 9 10007, 8, 8, 8, Total (JD), 9, 9 10008, 8, 8, 8, 0, Total (PP), 9 ; * find all variables with some text ; data _null_; set have end=last; array xchar{*} f1 - f6; length dropList $ 1024; retain dropList; drop i; * loop through all vars in array and check for text * if text is found check if we know this variable already * otherwise add it to the list *; do i = 1 to dim( xchar ); if upcase( xchar{i} ) in ("TOTAL (JD)", "TOTAL (PP)") then do; length varname $ 32; drop varname; varname = upcase( vname( xchar{i} ) ); if findw(dropList, varname, ",", "T") = 0 then do; dropList = catx(",", dropList, varname); end; end; end; * replace , by blank and write list into macro var ; if last = 1 then do; dropList = translate(dropList, " ", ","); putlog dropList=; call symputx("dropList", dropList); end; run; * create new DS and drop unwanted vars ; data want; set have; drop &dropList; run;
... View more