I have a dataset with 14000 obs and 200 variables.
There is a set of 54 character variables, named goname1-goname54, for which I want to set up an array and then search for a word/phrase within the variable values for goname1-goname54. Previously, I've successfully used both the array and the index functions, but I am unable to figure out how to do both in the same step.
For example, I want to create a new variable, called POT, that will be an index of whether any of the variables, goname1-goname54, contain the word 'potassium' (i.e., POT=1 if this word appears, and POT=0 if none of the variables contain this word.) In an attempt to do so, I've written the following program, but get all zeros for POT (and I know this is not correct):
data new;
set old;
array goname{1:54} $ 255 goname1-goname54;
flag = "potassium";
POT=0;
do i=1 to 54;
POT = index(goname{i}, flag);
end;
run;
I've also tried listing out all of the variable names (i.e., goname1 goname2 goname3...) after the array length statement, and also tried omitting the element length, among other attempts to manipulate the order of the program.
Any advice?
KDA
... View more