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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.