You can create it using the ARRAY statement in the DATA step:
data m(drop=i j);
array x[3];
do i = 1 to 5;
do j = 1 to dim(x);
x
end;
output;
end;
run;
proc print; run;
However, it's not clear what you're going to be able to do with it.
To find out some of the things that you can do with SAS/IML see the Getting Started articles.
Also see the book Statistical Programming with SAS/IML Software.
Rick: Do I happen to all of the sudden see colored code in your posts?
:smileygrin:
Rick,
Thanks for the code. In term of memory , does working with an array is more efficient than with a nested loop as Art suggested?
Art notes that the ARRAY statement can have multiple dimension (for example, two instead of the one-dimensional array that I used).
If you are going to try to use the DATA step to manipulate an array, a 2D array probably makes more sense. If your goal is to write a matrix to a data set, then my code is adequate and uses less memory because only one row of the matrix is ever in RAM.
I do need a 2d array, I would like to manipulate the array and I am kind of new to array in SAS. One more question if you don't mind.
Let's say i want to fill the array, the cell of row 2 and column 2 should be equal 0.8. How do I write this in SAS?
data foobar;
array x[3] (3*0);
do i=1 to 5;
do j=1 to dim(x);
x
end;
output;
end;
drop i j;
run;
proc print data=foobar; run
Obs x1 x2 x3
1 0.18496 0.97009 0.39982
2 0.25940 0.80000 0.96928
3 0.54298 0.53169 0.04979
4 0.06657 0.81932 0.52387
5 0.85339 0.06718 0.95702
Thanks so much!
Depending upon what you want to do with the matrix, you can always create a multi-dimensional array in SAS and fill it either with nested do loops are simply by initializing the cells with specific data.
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 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.