Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-16-2020 06:17 PM
(908 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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!

Multiple Linear Regression in SAS

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.