Hi Dave and welcome to LinuxQuestions!
It would be better if you'd show us what have you tried so far, so that we can be of help if you have specific questions. The script should do basically three operations for every file you want to move. A meta-code might be:
for file in *_test.dat
1. Extract the number from the file name (for example using grep)
2. Create the directory if it doesn't exist (mkdir -p could be useful in this case)
3. Move the file to the directory
The grep command could be something as
echo $file | grep -Eo '^[0-9]+'
but the regular expression strongly depends on the actual format of the file names (I mean of all
the files you want to move). Hope this helps a bit.