BookmarkSubscribeRSS Feed
Ksharp
Super User

Under the spring of this article:

https://communities.sas.com/t5/SAS-Communities-Library/Stepping-into-the-Matrix-in-SAS/ta-p/940095

Since it is about Matrix Graphic, I think it is more efficient and suitable by using SAS/IML Matrix code .

proc iml;
want=j(400,20,' ');
alphabet =('A':'Z') || ('0':'9');

do ncol=1 to ncol(want);
n=1;
do i=1 to int(nrow(want)/20);  /*the number of repeated string in a column*/
  temp=j(1,sample((1:10),1),' ')||sample(alphabet,sample((1:10),1),'wor');  /*randomly generated string*/
  len=ncol(temp);
  want[n:n+len-1,ncol]=t(temp);
  n=n+len;
end;
end;

row=row(want);
col=col(want);
temp_page=.;  /* int(nrow(want)/10) is the size of a page */
temp_value=' ';
temp_row=.;
temp_col=.;
create final_want var {temp_page temp_value temp_row temp_col};
do page=1 to nrow(want)-int(nrow(want)/10);  
  temp_page=colvec(j(int(nrow(want)/10),ncol(want),page));  /*a page or graph has 40 rows*/
  temp_value=colvec(t(want[page:page+int(nrow(want)/10)-1,]));
  temp_row=colvec(t(row[page:page+int(nrow(want)/10)-1,]));
  temp_col=colvec(t(col[page:page+int(nrow(want)/10)-1,]));
append ;
end;
close;
quit;
data final_want;
 set final_want;
 by temp_page;
 if first.temp_page or missing(temp_value) then group=0;
 if not missing(temp_value) then group+1;
run;

ods _all_ close;  
options nobyline papersize=('5 in', '5 in') animduration=0.2 animloop=yes noanimoverlay printerpath=gif animation=start nodate nonumber;
ods printer file='c:\temp\matrix.gif';
ods graphics / width=5in height=5in antialias noborder imagefmt=GIF;
proc sgplot data=final_want aspect=1 noborder  noautolegend;
by temp_page;
styleattrs backcolor=black wallcolor=black
datacontrastcolors=(white  CXFFFFCC CXD9F0A3 CXADDD8E CX78C679 CX41AB5D CX238443 CX005A32 CXF0F0F0 CXBDBDBD CX636363 );
scatter y=temp_row x=temp_col/  markerchar=temp_value group=group labelstrip markercharattrs=(weight=bold);
xaxis display=none;
yaxis display=none;
run;
options printerpath=gif animation=stop;
ods printer close;

matrix.gif

 

2 REPLIES 2
ClarkLawson
Obsidian | Level 7

Nice. Good to see other ways of achieving the same outcome with PROC IML.

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 831 views
  • 5 likes
  • 2 in conversation