Assuming that the part of the input files before the underscore is what you want to work on, you could get a list of those and loop around them something like this:-
for file_prefix in $(cut -f1 -d "_" input_file|sort -u)
do
unset input_params # Making sure that there is nothing left over from the previous file-prefix
for data_file in $(grep "^${file_prefix}_" input_file
do
input_params="${input_params} -I ${data_file}"
done
printf "Running the datamerge with parameters\n\t%s\nand writing to file\n\t%s\n\n" "${input_params}" "${file_prefix}.dat
./datamerge "${input_params}" -O "${file_prefix}.dat"
done
The printf is just to show you what it's doing, so you can check it is correct. You can remove it if you prefer.
You could add a counter to the inner loop if you want to report file counts. This also negates any concerns about missing files in the sequence, e.g. if you had these listing in your input file:-
would you want it to report four files and try to read Robin1_S101 to Robin_S104 and then fail because Robin1_S103.dat is missing or would you want it to use the names you have? You may prefer to fail and alert that something is missing, of course. That is, of course, your choice based on your requirement.
#!/bin/bash
# bash 4 required
declare -A arr
# Read the input file into the array
while IFS="_" read base ext
do
arr[$base]+=" -I ${base}_${ext}"
done < file
# Loop over the indices
for i in "${!arr[@]}"
do
echo ./datamerge "${arr[$i]}" -O "$i".dat
done
Omit the echo if you want to run the lines as commands.