Actually, the IDCAMS control cards to set up the GDG base should be a documented project deliverable and should be done before the JCL is created.
You could do it as amacro or you could read the JCL, procedure or otherwise, into your program. Scan each line looking for '(+', '(-', '(0'. Get the dataset name from the same line. Generate the IDCAMS statements. Store/write.
After that you will have to check the generated statements looking for duplicates - probably OK to use your sort product to remove them. Then manually adjust the statements to the requirements of each dataset - number of generations, what to do with them when they roll off etc.
The problem I have is that people can explain things quickly but I can only comprehend slowly.