/******************************************************************************
 * Programme : Prueba de Permutación Monte Carlo con PROC IML
 * Reference : PRUEBAE8F8
 * Source    : https://www.wearecas.eu/en/sampleCode/PRUEBAE8F8
 ******************************************************************************/

/* --- BLOC 1 --- */
data cash;
	input School Money;

datalines;
0 34
0 1200
...
1 3
1 0
;

/* --- BLOC 2 --- */
proc ttest data=cash;
	class School;
	var Money;
run;

/* --- BLOC 3 --- */
ods output off;
ods exclude all;

proc iml ;
	use cash;
	read all var{School Money} into x;
	p=t(ranperm(x[, 2], 1000));
	paf=x[, 1]||p;
	create newds from paf;
	append from paf;
	quit;

/* --- BLOC 4 --- */
ods output conflimits=diff;

proc ttest data=newds plots=none;
	class col1;
	var col2 -  col1001;
run;

ods output on;
ods exclude none;

/* --- BLOC 5 --- */
proc univariate data=diff;
	where method="Pooled";
	var mean;
	histogram mean;
run;

/* --- BLOC 6 --- */
data numdiffs;
	set diff;
	where method="Pooled";

	if abs(mean) >=114.6;
run;

/* --- BLOC 7 --- */
proc print data=numdiffs;
	where method="Pooled";
run;

