BookmarkSubscribeRSS Feed
Stephen_Q
Fluorite | Level 6

SAS Proc template Layoutlattice, How do I add a grid on the right of the cell to fill the text for each cell ? like as below PDF, I can only use    CELLHEADER  to add grid on top of cell, my code as below

 

%do k=&min_sub %to &max_sub;

cell;
cellheader;
entry textattrs=(color=black size=10pt weight=bold) "&&sub&k.." / border=true;
endcellheader;
layout overlay;

 

seriesplot x=x&k. y=y&k. / name="linechart"
group=visit2
lineattrs=(thickness=2 pattern=Solid);

scatterplot x=xx&k. y=yy&k. / name="scatter"
group=abpmfl2;

endlayout;
endcell;
%end;

 

5 REPLIES 5
ballardw
Super User

What text? How much text do you expect? What variable holds the text?

 

With graphic questions it is best to provide  1) some example data so we have a chance to test suggestions

2) the complete code you are using/starting with. There are so many interactions with elements in graphs we really should see all of them. With GTL code also the expected Proc Sgrender call.

 

Not to mention a source for all of the macro variables.

 

I think you may be looking for some flavor of row2axes.

Stephen_Q
Fluorite | Level 6
Thank you very much for your reply! About 10 letters per cell. I'm going to store it in a macro variable. For example, I want to draw a graphic which column=2 and row=3 . Can you fill in "AAAAAAAAAA" on each cell(on the right of cell) ? If you can then I know how to do. I can only use CELLHEADER to add grid to fill the text on top of cell now. I'm sorry that I can't upload data.You can use any data test in sashelp library. My full code as below %macro figure; proc sql noprint; select max(ord_param) into: max_param from adeg5; quit; %do o=1 %to &max_param; proc sql noprint; select max(ord_trt) into: max_trt from adeg5 where ord_param=&o; quit; %do i=1 %to &max_trt; proc sql noprint; select max(ord_pg) into: max_pg from adeg5 where ord_param=&o and ord_trt=&i; quit; %do p=1 %to &max_pg; data b; set adeg5; where ord_param=&o and ord_trt=&i and ord_pg=&p; run; proc sql noprint; select min(ord_sub) into: min_sub from b; select max(ord_sub) into: max_sub from b; select distinct(visit) into: legend separated by"," from b; quit; %do sub=1 %to &max_sub; proc sql noprint; select distinct(asubjid) into: sub&sub.- from b where ord_sub=⊂ ; select min(y&sub.) into: miny&sub.- from b where ord_sub=⊂ ; select max(y&sub.) into: maxy&sub.- from b where ord_sub=⊂ ; quit; %end; proc template; define statgraph linechart; begingraph/ designwidth=8.0in border=false; discreteattrmap name="l" / ignorecase=true ; value "A" /markerattrs=(color=green symbol=circle) lineattrs=(color=green pattern=solid ); value "B" /markerattrs=(color=blue symbol=circle) lineattrs=(color=blue pattern=solid ); value "C" /markerattrs=(color=red symbol=circle) lineattrs=(color=red pattern=solid ); value "D" /markerattrs=(color=yellow symbol=circle) lineattrs=(color=yellow pattern=solid ); enddiscreteattrmap ; discreteattrvar attrvar=visit2 var=visit attrmap="l" ; %if %index(%quote(&legend),%str(A)) >0 %then %do; legendItem type=markerline name="A" / markerattrs=(color=green symbol=Circle) lineattrs=(color=green pattern=solid thickness=2) label="A"; %end; %if %index(%quote(&legend),%str(B)) >0 %then %do; legendItem type=markerline name="B" / markerattrs=(color=blue symbol=Circle) lineattrs=(color=blue pattern=solid thickness=2) label="B"; %end; %if %index(%quote(&legend),%str(C)) >0 %then %do; legendItem type=markerline name="C" / markerattrs=(color=red symbol=Circle) lineattrs=(color=red pattern=solid thickness=2) label="C"; %end; %if %index(%quote(&legend),%str(D)) >0 %then %do; legendItem type=markerline name="D" / markerattrs=(color=yellow symbol=Circle) lineattrs=(color=yellow pattern=solid thickness=2) label="D"; %end; layout globallegend / border=true type=column %if &ad="M" and &max_sub^=1 %then %do; halign=center;%end; %if &ad="M" and &max_sub=1 %then %do; halign=left;%end; %if &ad="S" %then %do; halign=center;%end; discretelegend "A" "B" "C" "D" /autoitemsize=false DISPLAYCLIPPED=true %if &ad="S" %then %do;across=4;%end; %if &ad="M" %then %do;across=3;%end; endlayout; entrytitle textattrs=(color=black size=10pt weight=bold) "&&t&i.."; layout lattice/ columns = &col1. rows = &row1. rowweights=uniform rowdatarange=union columndatarange=union rowgutter=0.5 columngutter=0.5 skipemptycells=true pad=(left=40); rowaxes; %do j=1 %to &row1.; rowaxis/type=linear display=(line ticks tickvalues) %if &o=1 %then %do; linearopts=(tickvaluesequence=(start=40 end=160 increment=40) viewmin=40 viewmax=160); %end; %if &o=2 %then %do; linearopts=(tickvaluesequence=(start=30 end=120 increment=30) viewmin=30 viewmax=130); %end; %if &o=3 %then %do; linearopts=(tickvaluesequence=(start=30 end=120 increment=30) viewmin=30 viewmax=120); %end; %end; endrowaxes; columnaxes; %do l=1 %to &col1.; columnaxis/type=linear display=(line ticks tickvalues) linearopts=(tickvaluelist=(0 1 6 12 18 24) viewmin=-1 viewmax=25); %end; endcolumnaxes; drawtext textattrs=(color=black size=10pt weight=bold) "&&P&o.."/ anchor=BOTTOM width=80 widthunit=percent ROTATE=90 x=5 y=50 justify=center ; %do k=&min_sub %to &max_sub; cell; cellheader; entry textattrs=(color=black size=10pt weight=bold) "&⊂&k.." / border=true; endcellheader; layout overlay; seriesplot x=x&k. y=y&k. / name="linechart" display=(markers) group=visit2 lineattrs=(thickness=2 pattern=Solid); endlayout; endcell; %end; SIDEBAR / ALIGN=bottom; ENTRY "Hours" ; ENDSIDEBAR; endlayout; endgraph; end; run; proc sgrender data=b template=linechart; run; %end; %end; %end; %mend; %figure;
Stephen_Q
Fluorite | Level 6

Thank you very much for your reply. Sorry about the mess, I'm putting code in the PDF now. If you know how to do, could you show your code? Thank you very much!

ballardw
Super User

Code is typically best in a code box opened on the forum with the </> icon that appears above the message window. That will preserve indenting and such when pasting text that is copied from the editor.

 

I don't see anything resembling data. Also a source for the text you expect to display, such as a data set is a good idea along with where you expect it to appear.

 

 

Stephen_Q
Fluorite | Level 6

Thank you very much for your reply!

About 10 letters per cell. I'm going to store it in a macro variable.

For example, I want to draw a graphic which column=2 and row=3 .

Can you fill in "AAAAAAAAAA" on each cell(on the right of cell) ?

If you can then I know how to do. Attached file(PDF3) show where I expect it to appear.

I can draw the first graphic, but I can't draw the second graphic.

I can only use  CELLHEADER  to add grid to fill the text on top of cell now.

I'm sorry that I can't upload data.You can use any data test in sashelp library.

If you know how to do, could you show your code? 

My full code as below

 

 

 

 

 

%macro figure;

 

proc sql noprint;

  select max(ord_param) into: max_param from adeg5;

quit;

 

%do o=1 %to &max_param;

 

proc sql noprint;

  select max(ord_trt) into: max_trt from adeg5 where ord_param=&o;

quit;

 

%do i=1 %to &max_trt;

 

proc sql noprint;

  select max(ord_pg) into: max_pg from adeg5 where ord_param=&o and ord_trt=&i;

quit;

 

%do p=1 %to &max_pg;

 

data b;

  set adeg5;

  where ord_param=&o and ord_trt=&i and ord_pg=&p;

run;

 

proc sql noprint;

  select min(ord_sub) into: min_sub from b;

  select max(ord_sub) into: max_sub from b;

  select distinct(visit) into: legend separated by"," from b;

quit;

 

%do sub=1 %to &max_sub;

 

proc sql noprint;

  select distinct(asubjid) into: sub&sub.- from b where ord_sub=&sub ;

  select min(y&sub.) into: miny&sub.- from b where ord_sub=&sub ;

  select max(y&sub.) into: maxy&sub.- from b where ord_sub=&sub ;

quit;

 

%end;

 

proc template;

  define statgraph linechart;

  begingraph/ designwidth=8.0in border=false;

 

  discreteattrmap name="l" / ignorecase=true ;

  value "A" /markerattrs=(color=green  symbol=circle)

  lineattrs=(color=green pattern=solid );

  value "B" /markerattrs=(color=blue  symbol=circle)

  lineattrs=(color=blue pattern=solid );

  value "C" /markerattrs=(color=red  symbol=circle)

  lineattrs=(color=red pattern=solid );

  value "D" /markerattrs=(color=yellow  symbol=circle)

  lineattrs=(color=yellow pattern=solid );

 

 

  enddiscreteattrmap ;

  discreteattrvar attrvar=visit2 var=visit attrmap="l" ;

 

  %if %index(%quote(&legend),%str(A)) >0 %then %do;

  legendItem type=markerline name="A" / markerattrs=(color=green symbol=Circle) lineattrs=(color=green pattern=solid thickness=2) label="A";

  %end;

  %if %index(%quote(&legend),%str(B)) >0 %then %do;

  legendItem type=markerline name="B" / markerattrs=(color=blue symbol=Circle) lineattrs=(color=blue pattern=solid thickness=2) label="B";

  %end;

  %if %index(%quote(&legend),%str(C)) >0 %then %do;

  legendItem type=markerline name="C" / markerattrs=(color=red symbol=Circle) lineattrs=(color=red pattern=solid thickness=2) label="C";

  %end;

  %if %index(%quote(&legend),%str(D)) >0 %then %do;

  legendItem type=markerline name="D" / markerattrs=(color=yellow symbol=Circle) lineattrs=(color=yellow pattern=solid thickness=2) label="D";

  %end;

 

 

 

  layout globallegend / border=true type=column

  %if &ad="M" and &max_sub^=1 %then %do; halign=center;%end;

  %if &ad="M" and &max_sub=1 %then %do; halign=left;%end;

  %if &ad="S" %then %do; halign=center;%end;

  discretelegend  "A" "B" "C" "D"

   /autoitemsize=false  DISPLAYCLIPPED=true

  %if &ad="S" %then %do;across=4;%end;

  %if &ad="M" %then %do;across=3;%end;

  endlayout;

 

  entrytitle textattrs=(color=black size=10pt weight=bold) "&&t&i..";

 

  layout lattice/ columns = &col1. rows = &row1. rowweights=uniform  rowdatarange=union columndatarange=union

  rowgutter=0.5 columngutter=0.5 skipemptycells=true pad=(left=40);

 

                rowaxes;

%do j=1 %to &row1.;

                        rowaxis/type=linear display=(line ticks tickvalues)

    %if &o=1  %then %do;

                        linearopts=(tickvaluesequence=(start=40 end=160 increment=40) viewmin=40 viewmax=160);

    %end;

         %if &o=2 %then %do;

                        linearopts=(tickvaluesequence=(start=30 end=120 increment=30) viewmin=30 viewmax=130);

    %end;

    %if &o=3 %then %do;

                        linearopts=(tickvaluesequence=(start=30 end=120 increment=30) viewmin=30 viewmax=120);

    %end;

                    

%end;

                endrowaxes;

 

      columnaxes;

                     %do l=1 %to &col1.;

                        columnaxis/type=linear display=(line ticks tickvalues)

                        linearopts=(tickvaluelist=(0 1 6 12 18 24) viewmin=-1 viewmax=25);

                     %end;

                endcolumnaxes;

 

    drawtext textattrs=(color=black size=10pt weight=bold) "&&P&o.."/

    anchor=BOTTOM  width=80 widthunit=percent ROTATE=90

    x=5 y=50 justify=center ;

 

  %do k=&min_sub %to &max_sub;

  cell;

  cellheader;

 entry textattrs=(color=black size=10pt weight=bold) "&&sub&k.." / border=true;

 endcellheader;

  layout overlay;

 

    seriesplot x=x&k. y=y&k. / name="linechart" display=(markers)

    group=visit2

    lineattrs=(thickness=2 pattern=Solid);

 

 

  endlayout;

  endcell;

  %end;

  

  SIDEBAR / ALIGN=bottom;

    ENTRY "Hours" ;

  ENDSIDEBAR;

 

  endlayout;

 

 

  endgraph;

 end;

run;

 

proc sgrender data=b template=linechart;

run;

 

%end;

%end;

%end;

%mend;

%figure;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1146 views
  • 0 likes
  • 2 in conversation