The DO loop in SAS/IML does not support the comma syntax, thus the statement
do i=21 to 30, 51 to 60;
is invalid.
Instead, put those values into a vector and use vectorized subscript computations:
idx = (21:30) || (51:60);
F1 = b[,1]; F2 = b[,2];
ss = sum( F1[idx]=0 & F2[idx]=1 );
print ss;
The vectorized computation is faster and simpler than the equivalent computation that uses loops:
/* you could do this, but not efficient */
F1 = b[,1]; F2 = b[,2];
ss=0;
do i=21 to 30;
If ( F1[i] =0) & (F2[i]=1) then ss=ss+1;
end;
do i=51 to 60;
If ( F1[i] =0) & (F2[i]=1) then ss=ss+1;
end;
print ss;
By the way, the data you posted seems to be corrupted. In the future please paste code into the SAS Code Window by clicking the "running man icon" in the editor while posting your question,
I'm guessing that you mean proc optmodel. Yes you can, but why?
You have to be more specific than this, otherwise it is imposible to help you.
What do you have already?
For simulation and optimization, I recommend SAS/IML. It is easy to write a loop that simulates data, computes or optimizes some quantity, and stores the results. search for your relevant terms at The DO Loop blog. For example, search
optimize simulation site:blogs.sas.com/content/iml
Please post your code so that we can help you. Also, describe the problem you are trying to solve.
The DO loop in SAS/IML does not support the comma syntax, thus the statement
do i=21 to 30, 51 to 60;
is invalid.
Instead, put those values into a vector and use vectorized subscript computations:
idx = (21:30) || (51:60);
F1 = b[,1]; F2 = b[,2];
ss = sum( F1[idx]=0 & F2[idx]=1 );
print ss;
The vectorized computation is faster and simpler than the equivalent computation that uses loops:
/* you could do this, but not efficient */
F1 = b[,1]; F2 = b[,2];
ss=0;
do i=21 to 30;
If ( F1[i] =0) & (F2[i]=1) then ss=ss+1;
end;
do i=51 to 60;
If ( F1[i] =0) & (F2[i]=1) then ss=ss+1;
end;
print ss;
By the way, the data you posted seems to be corrupted. In the future please paste code into the SAS Code Window by clicking the "running man icon" in the editor while posting your question,
1. The running man icon looks like this:
2. Sorry, I didn't realize you had read the variables into the matrix B. I have edited my previous answer to add the line
F1 = b[,1]; F2 = b[,2];
which extracts the first column of B into the vector F1 and the second column into the vector F2.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.