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;
> Does an IML action run automatically on several nodes?
No, it doesn't. Your session determines how many nodes are available, but the program only uses multiple nodes for distributed functions. Examples of a distributed function are MapReduce, ParTasks, and reading/writing CAS tables. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_026/casactiml/casactiml_iml_details08.htm
> Or do I have to use the 'nthreads' option?
The NTHREADS= option determines how many threads are available on each node. But only multithreaded operations use the threads. Multithreaded operations include the distributed functions (as above) and linear algebra operations such as SOLVE and SVD. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_029/casimllang/casimllang_common_sect015.htm#cas...
With the exception of the read/write operations, your program will run in a single thread on the controller node.
I cannot determine what your program is supposed to do, but if you explain it a little and include some example data, we might be able to offer a way to improve its efficiency.
> Does an IML action run automatically on several nodes?
No, it doesn't. Your session determines how many nodes are available, but the program only uses multiple nodes for distributed functions. Examples of a distributed function are MapReduce, ParTasks, and reading/writing CAS tables. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_026/casactiml/casactiml_iml_details08.htm
> Or do I have to use the 'nthreads' option?
The NTHREADS= option determines how many threads are available on each node. But only multithreaded operations use the threads. Multithreaded operations include the distributed functions (as above) and linear algebra operations such as SOLVE and SVD. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_029/casimllang/casimllang_common_sect015.htm#cas...
With the exception of the read/write operations, your program will run in a single thread on the controller node.
I cannot determine what your program is supposed to do, but if you explain it a little and include some example data, we might be able to offer a way to improve its efficiency.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.