I have a dataset with 2000 observations. It contains ID, var1, var2. Var1="11,21,43,35" or "11" or any combination of these numbers. sometimes just one number, sometimes two numbers. Var2="20,21,35,43" or or any combination of these numbers. sometimes just one number, sometimes two numbers. I would like to generate a new variable to find any overlap or matching numbers between these two variables. For example, when var1="11,21,43,25" and var2="20,21,35,43" then matching="21"; when var1="11" and var2="35" then matching=.; when var1="11,21,35" and var2="21,35,43" then matching="21,35". Data want; input ID var1 $ var2 $; datalines; 1 11,21,43,35 11 2 11,21,43,25 20,21,35,43 3 11 35 4 11,21,35 21,35 5 21 35,21,43 ; Any suggestions would be greatly appreciated.
... View more