I have to replace the program name in steps from JCL, but only if I find some data later.
For example I want to replace OLPGM by NEWPGM only if I found the string "PARM0001" somewhere later in the step.
You have one piece of JCL you want to do this to, or a library full?
If the latter, a general-purpose programming language would be a better choice. Probably.
Is the value you are looking for only in data-cards (and only data-cards which don't begin with //)?
A JOINKEYS using the same dataset for both inputs.
In JNF1CNTL, use WHEN=INIT to PARSE by "word" (for the first two) and use WHEN=GROUP to PUSH a sequence number when the second PARSEd field is EXEC and the first begins with // and doesn't have an * in column three.
In JNF2CNTL, OMIT COND= for "//b" (where b is blank) and "//*. Do the same PARSE and GROUP as above and then use WHEN=(logicalexpression) to clobber the SEQ for any card which begins //. Another WHEN=(logicalexpression) to clobber any which does not contain your value (you can use SS, perhaps PARSE, unless your positions and lengths are rigorous).
JOINKEYS to specify SORTED and NOSEQCK.
REFORMAT to contain F1 and the matched-marker.
In the main task, you'll need to PARSE to find the EXEC card and make the change.
Two hits of your value in the same data will mess things up.
You need to watch for JCL comments, JECL and even for /* cards where someone has added text to it. Also check for possibility of value appearing in DSN, or other information relating to JCL cards.