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

 

1 REPLY 1
ClarkLawson
Obsidian | Level 7

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 249 views
  • 3 likes
  • 2 in conversation