The data (x, y points) are generated entirely within the PROC IML block by an iterative process, then stored in the temporary 'IFS' dataset. No external data or data from SASHELP is used for the main generation.
1 Code Block
PROC IML Data
Explanation : This block initializes the linear transformation matrices (L), translation vectors (B), and probabilities for an iterated function system, specifically configured to generate a Christmas tree. It then performs 100,000 iterations using the `randgen` function to randomly select a transformation. Each iteration calculates a new point based on the previous one. The generated points (x, y) are then transcoded and stored in a temporary SAS dataset named 'IFS', which will be used for visualization.
Copied!
proc iml;
/* For an explanation of how to construct an iterated function system in SAS, see
http://blogs.sas.com/content/iml/2012/12/12/iterated-function-systems-and-barnsleys-fern-in-sas/
*/
/* Each row is a 2x2 linear transformation */
/* Christmas tree */
L = {0.03 0 0 0.1,
0.85 0.00 0.00 0.85,
0.8 0.00 0.00 0.8,
0.2 -0.08 0.15 0.22,
-0.2 0.08 0.15 0.22,
0.25 -0.1 0.12 0.25,
-0.2 0.1 0.12 0.2};
/* ... and each row is a translation vector */
B = {0 0,
0 1.5,
0 1.5,
0 0.85,
0 0.85,
0 0.3,
0 0.4 };
prob = { 0.02 0.6 0.1 0.07 0.07 0.07 0.07};
L = L`; B = B`; /* For convenience, transpose the L and B matrices */
/* Iterate the discrete stochastic map */
N = 1e5; /* number of iterations */
x = j(2,N); k = j(N,1);
x[,1] = {0, 2}; /* initial point */
call randgen(k, "Table", prob); /* values 1-7 */
do i = 2 to N;
x[,i] = shape(L[,k[i]], 2)*x[,i-1] + B[,k[i]]; /* iterate */
end;
/* Plot the iteration history */
y = x`;
create IFS from y[c={"x" "y"}]; append from y; close IFS;
quit;
1
PROC IML;
2
/* For an explanation of how to construct an iterated function system in SAS, see
create IFS from y[c={"x""y"}]; append from y; close IFS;
38
QUIT;
2 Code Block
PROC SGPLOT
Explanation : This block configures the ODS Graphics destination system to set the output image size (200px wide by 400px high). Then, PROC SGPLOT is used to create a scatter plot from the previously generated 'IFS' dataset. Marker attributes are set with a small size (1) and a ForestGreen color to simulate the appearance of the tree's needles. The Y and X axes are disabled to produce a clean image of the tree.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.