¡Hi everybody!
I am trying to get a matrix with all the possibles combinations of "0 and 1" i have seen the function "IML" but i not have access to that function,would it be possible por me program all that?
i am with this one:
/*just create three data sets (all hold 0,1)*/
data a;
input x@@;
datalines;
0 1
;
data b;
input y@@;
datalines;
0 1
;
data c;
input z@@;
datalines;
0 1
;
/*use Cartesian product to get all the 2*2*2 combinations*/
proc sql;
create table all as
select *
from a,b,c
order by x,y,z
;
quit;
proc print nobs;run; but what if i want to get into a lot of more data? i mean maximum 1555030x1555030 with all the combinations (0 and 1) possibles, sql doest not allowed me to do that.
Thank you so much for your help.
I am trying to generate a loss probability distribution.
There are several ways I can think of to get the matrix you want. For example PROC PLAN will produce a matrix of 1s and 2s :
proc plan;
factors x=2 ordered y=2 ordered z=2 ordered;
output out=all;
run;
Alternatively consider GRAYCODE which you can use like this:
data all (drop = i k);
array x(3);
k = -1;
do i = 1 to 2**3;
call graycode(k, of x(*) );
output;
end;
run;
Having a loop is an advantage, as you could add an IF statement to only output the possibilities that you are interested in.
However, you will never be able to process 2 ^ 1,555,043 possibilites as this number is far too big! Even 2 ^ 30 is pushing against limits, as this is above 1 billion.
I think you will need a more sophisticated approach, but you will need to give more details on what you want to achieve, to get any useful help. If you do not have IML, then it would be better to ask this question in a different forum.
This isn't that clear.
Are you required to use IML? If you only have two values why do you have so many options?
I think you need to further explain your issue.
You can look at the documentation for ALLCOMB or CALL ALLCOMB on other ways to create all possible combinations of data.
Thank you so much for your time!!
Yeaap,sorry i was not that clear,see i am an actuarie working for a BANK, i am trying to do this:
Suppose i have this:
Portfolio | |
Default probability | exposure |
0.06 | 1,000,000.00 |
0.05 | 780,000.00 |
0.04 | 500,000.00 |
0.02 | 250,000.00 |
0.01 | 100,000.00 |
then i am creating all the possibles combinations for that 5 number of persons with just a flag(1 or 0) ,with 1 (default) and 0(no default) then i have the combinations: 2^5 i mean 2^n., generating this:
Case | X1 | X2 | X3 | X4 | X5 |
1 | 1 | 1 | 1 | 1 | 1 |
2 | 1 | 1 | 1 | 1 | 0 |
3 | 1 | 1 | 1 | 0 | 1 |
4 | 1 | 1 | 1 | 0 | 0 |
5 | 1 | 1 | 0 | 1 | 1 |
6 | 1 | 1 | 0 | 1 | 0 |
7 | 1 | 1 | 0 | 0 | 1 |
8 | 1 | 1 | 0 | 0 | 0 |
9 | 1 | 0 | 1 | 1 | 1 |
10 | 1 | 0 | 1 | 1 | 0 |
11 | 1 | 0 | 1 | 0 | 1 |
12 | 1 | 0 | 1 | 0 | 0 |
13 | 1 | 0 | 0 | 1 | 1 |
14 | 1 | 0 | 0 | 1 | 0 |
15 | 1 | 0 | 0 | 0 | 1 |
16 | 1 | 0 | 0 | 0 | 0 |
17 | 0 | 1 | 1 | 1 | 1 |
18 | 0 | 1 | 1 | 1 | 0 |
19 | 0 | 1 | 1 | 0 | 1 |
20 | 0 | 1 | 1 | 0 | 0 |
21 | 0 | 1 | 0 | 1 | 1 |
22 | 0 | 1 | 0 | 1 | 0 |
23 | 0 | 1 | 0 | 0 | 1 |
24 | 0 | 1 | 0 | 0 | 0 |
25 | 0 | 0 | 1 | 1 | 1 |
26 | 0 | 0 | 1 | 1 | 0 |
27 | 0 | 0 | 1 | 0 | 1 |
28 | 0 | 0 | 1 | 0 | 0 |
29 | 0 | 0 | 0 | 1 | 1 |
30 | 0 | 0 | 0 | 1 | 0 |
31 | 0 | 0 | 0 | 0 | 1 |
32 | 0 | 0 | 0 | 0 | 0 |
i have read about iml but i don´t have such a function,i am nor advanced at macros but the previous code i left seems to me to have the logic, it is just that i do not know how to construct this matriz since i don't have iml. My maximum number of clients is 1,555,043 and i am expecting tgis matrix to be 2^1,555,043 in order to get all the cambinations and finally get mi distribution.
Thank you so so much for your time.
Best regards.
Fátima.
I'm still confused. Do you want to use IML or another SAS procedure to do this?
Hi,
No IML,I need another procedure.
Hi,
No IML,I need another procedure.
Thank you.
You posted this in IML.
I'm not sure what you want is feasible. It's possible but I wonder if a different structure wouldn't work better. Can you explain what you will do with the matrix after it's created.
There are several ways I can think of to get the matrix you want. For example PROC PLAN will produce a matrix of 1s and 2s :
proc plan;
factors x=2 ordered y=2 ordered z=2 ordered;
output out=all;
run;
Alternatively consider GRAYCODE which you can use like this:
data all (drop = i k);
array x(3);
k = -1;
do i = 1 to 2**3;
call graycode(k, of x(*) );
output;
end;
run;
Having a loop is an advantage, as you could add an IF statement to only output the possibilities that you are interested in.
However, you will never be able to process 2 ^ 1,555,043 possibilites as this number is far too big! Even 2 ^ 30 is pushing against limits, as this is above 1 billion.
I think you will need a more sophisticated approach, but you will need to give more details on what you want to achieve, to get any useful help. If you do not have IML, then it would be better to ask this question in a different forum.
I see absolutely no connection between your "Portfolio" information and the example desired output;
This macro makes a data set named Want with the desired output though the 0 values come first. If you don't like that change the
do x&i=0 to 1 into do x&i = 1 to 0 by (-1);
%macro dummy(numPers); data want; retain case 0; %do i=1 %to &numpers; do x&i = 0 to 1; %end; case +1; output; %do i=1 %to &numpers; end; %end; run; %mend; %dummy(5);
%let n=5; %let x=%substr(%qsysfunc(repeat(%str(,0:1),&n)),2); %put &x ; proc iml; want=expandgrid(&x); print want; quit;
I moved this post to Base SAS forum.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.