Obsidian | Level 7

## Shape Function in IML

Can anyone tell me what the following line of code does:

X1=X;

do i=1 to 24;

do k=1 to 4;

X[,indices[i,k]+1]=shape(0,nrow(X1),1);

end;

end;

X is a 200 row by 5 column matrix of 1's and 0's.

indices is a 24 row by 4 column matrix with the numbers 1 to 4 in different order for each row.

5 REPLIES 5
Super User

## Re: Shape Function in IML

Are you able to post your entire IML code?

Otherwise, see if the SHAPE Function Doc helps you.

Obsidian | Level 7

## Re: Shape Function in IML

This is the entire code that someone wrote. It's just the shape function that doesn't make sense to me.

%macro averageAF (out, riskfactors, data);

proc logistic data=&data descending outdesign=_design_ outest=_model_ noprint;
model &out = &riskfactors;
run;

%let vars=1;
%let names=;
%do %while (%Qscan(&riskfactors,&vars) ne );
%let names=&&names %Qscan(&riskfactors,&vars);
%let vars=%eval(&vars+1);
%end;
%let vars=%eval(&vars-1);

%put &names;

data _design_;
set _design_;
if nmiss(of &riskfactors)=0 and nmiss(of &out)=0;
run;

data _indices_;
drop i perms;
array x (&vars) (1:&vars);

perms=fact(&vars);
/*vars=4 and perms=24*/
do i=1 to perms;
call allperm(i, of x(*));
output;
end;
run;

proc iml;
use _design_;
read all var {intercept &riskfactors} into X;
close _design_;
use _model_;
read var {intercept &riskfactors} into beta;
close _model_;
use _indices_;
read all var _num_ into indices;
close _indices_;

start pp(pcases,X,beta);
pcases=sum(1/(1+exp(-X*beta`)));
finish;

run pp(pcases,X,beta);

print (pcases);

pred_cases_m=shape(.,nrow(indices),&vars); /*24 rows , 4 columns*/
prev_cases_m=shape(.,nrow(indices),&vars); /*24 rows , 4 columns*/

X1=X;
do i=1 to nrow(indices); /*24*/
do k=1 to &vars; /*4*/
print (indices[i,k]);
X[,indices[i,k]+1]=shape(0,nrow(X1),1);
pred_cases_m[i,k]=sum(1/(1+exp(-X*beta`)));
print (pred_cases_m[i,k]);
end;
X=X1;
end;

Barite | Level 11

## Re: Shape Function in IML

The code does not make much sense to me.  The SHAPE function is being used to generate a vector of zeros and then that vector is being copied repeateadly into columns 2 to 5 of X.  I believe the one line

``X [ , 2:5] = 0;``

would have the same effect as the double loop.   But you need to test this out - try printing the matrix X before and after.

Barite | Level 11

## Re: Shape Function in IML

I notice that the line "X = X1" is missing from the first code example that you posted. With this line the code makes more sense as X is reset after each iteration of the outermost loop.  The result is that the columns of X are set to zero in every possible order.

SAS Super FREQ

## Re: Shape Function in IML

Has your question been resolved? If so, please mark an answer as correct and close this thread. If not, what questions remain and how can we help?

From The DO Loop