I assume you have a chi-square test for each of several groups, and that the groups are all stacked in the same data file. The specific approach will depend on which PROC you are using (FREQ, etc.). You should first be able to get the displayed output for each group (using by statement) for the desired PROC. The general instruction is to find the ODS output table name for the specific procedure that contains the test statistics, P values, etc. Store this table as a file, as explained for use of ODS, in general. Then, perform an IF-THEN operation on this file, and then print this new file.
Can't give more specific instructions until you first get the procedure running.