This problem represents what my former organization called a "multiple response" variable, where a single respondent could have one or more valid responses (in our case it was to questions like "with which languages are you fluent").
We had a number of purpose-built analytical tools to use with these variables, but the only general-purpose approach that I found useful was to create a long, thin table with a respondent ID and each of the one to many responses on a separate row.
The following code should create something similar for you, with some simulated data that I created.
You can then use SQL to find the ID values that match combinations, like "6677", or "7012 and 3576", or "0625 and 4824 but not 3367".
Give it a try with a small-scale example, and see if it's going in the right direction.
Tom
data have;
infile cards dlm='09'x;
length ID 8 CharacterString $500;
input ID CharacterString;
cards;
1 7051-3984,7514-7594,6843-6848,6677-6685,1212-6561
2 9705,9638,7460
3 2725,6929,3576,6386,7012,7488,3998,6907,9846
4 3056,7596,9945,5488,4457
5 4824,3367,4625,0625,9752,0981,0413,2066,3463
6 1117
run;
data want(keep=ID XCode);
set have;
length XCode $4;
WordNumber = 1;
XCode = scan(CharacterString, WordNumber, ",-", "o");
do while(^missing(XCode));
output;
WordNumber = WordNumber + 1;
XCode = scan(CharacterString, WordNumber, ",-", "o");
end;
run;
... View more