Or do I have to use the 'nthreads' option?
My code runs successfully but it takes a long time to execute.
options casdatalimit=all;
proc cas;
loadactionset 'iml'; /* load the iml action set (only once per session) */
run;
source imly;
KeepStmt1 = 'KEEP=codidoc codopera ';
KeepStmt2 = 'KEEP=_numeric_ ';
KeepStmt3 = 'KEEP=QNUMMESE ';
x = matrixCreateFromCAS('PUBLIC', 'exp2', KeepStmt2 );
y=matrixCreateFromCAS('PUBLIC', 'EXP2', KeepStmt1);
QNUMMESE = matrixCreateFromCAS('PUBLIC', 'EXP2', KeepStmt3);
varnames={&var2s.};
X=X||J(NROW(X),1,0);
XT=(SHAPE(DIF(X), NROW(X)) [, 2:NCOL(X)])#2;
idx=loc((x[, 2:NCOL(X)]+xt)=1);
xt[idx]=1;
y=y[,2]||y[,1];
t2=unique(qnummese);
/* rowhead=char(t2); */
t22=(repeat(t2, nrow(x))=qnummese)`*(xt = 2);
t22_sum=t22 [+];
ctr=(xt = 2) [+];
idx1=loc(t22 <> 0);
s = ndx2sub(dimension(t22), idx1);
/* PRINT QNUMMESE y XT T2 T22 T22_SUM CTR IDX1 S; */
res0=j(nrow(s), ncol(x)-1, .);
res0_perc=res0;
do i=1 to ncol(idx1);
idx2=loc( ( (qnummese=t2[s[i,1]])# (xt[, s[i,2]]=2) )=1);
/* PRINT IDX2; */
res0[i,s[i,2]] = t22[idx1[i]];
/* PRINT RES0; */
res0[i,(s[i,2]+1):ncol(xt)]=(x [loc(element(y[,1], y[idx2,1])),(s[i,2]+1):ncol(x)-1] <>0) [+,];
/* PRINT RES0; */
res0_perc[i,(s[i,2]):ncol(xt)]=res0[i,(s[i,2]):ncol(xt)]/res0[i,s[i,2]];
end;
/* endsource; */
/* iml / code=imly; */
/* run; */
rown=catx("|", t2 [s[,1]], varnames[s[,2]]);
call MatrixWriteToCAS(res0, '', '_crm_fun', varnames);
call MatrixWriteToCAS(res0_perc, '', '_crm_fun_perc', varnames);
call MatrixWriteToCAS(rown, '', '_crm_fun_id');
endsource;
iml / code=imly;
run;