SAS Chi-square Test

#4
More details

What I need is a function that will return the double sum of (Oij - eij)^2/eij where Oij is the observed frequency and eij is the expected frequency. Also we get our values from a probrobility table.
 
#5
If that is the case then you need to use PROC FREQ:

proc freq data=dataset noprint;
tables var1*var2 / outexpected out=output_dataset;
run;

Option "outexpected" outputs the expected frequency in the dataset specified in option "out=".
To automate the calculations you could use a macro which takes the name of the dataset and the variables you want to cross-tabulate. Then you will have to use a DATA STEP to complete your calculations.