BookmarkSubscribeRSS Feed
CharlieHe
Fluorite | Level 6
I tried to modify a plot macro which was used for Stepplot and replaced Stepplot with Barchart. The bar chart are shown OK but the bottom 3 blockplots disappeared. I tried back and forth several time and still cannot figure out what is wrong.

Thanks a lot.
Yeming

Here is the data and code:

data freqout;
input window $10. order grptot1 grptot2 grptot3 grppct1 grppct2 grppct3;
datalines;
BASELINE 1 198 205 182 97.980 97.561 96.154
WEEK 6 2 5 14 12 100.000 100.000 83.333
WEEK 12 3 179 179 155 97.207 95.531 96.129
WEEK 18 4 6 7 3 100.000 100.000 66.667
WEEK 26 5 76 73 64 96.053 94.521 100.000
END POINT 6 186 190 166 96.237 96.316 98.193
run;
proc print;
run;

%let program=test01;
%let analset=Intent-to-Treat Analysis Set;
%let test01=Bar Plot of Proportion of Subjects with HbA1c < 7% over Time;

%macro BarPlot(inds=, title1=, title2=, title3=, ylabel=);

proc template;
define statgraph Gtl_Bars;
dynamic win;
mvar locate sysdate;

begingraph;

entrytitle textattrs=(weight=bold size=11 family="Times New Roman") "&title1";
entrytitle textattrs=(weight=normal size=9 family="Times New Roman") "&title2";;
entrytitle "&title3";;

entryfootnote textattrs=(weight=normal size=8 family="Times New Roman") halign=left "Created on " SYSDATE;

layout lattice / rows=5 columndatarange=union rowweights=(0.84 .04 .04 .04 .04);

layout overlay / cycleattrs=true ;

/* Stepplot is OK */

/*
stepplot x=order y=grppct1 / name='grp1';
stepplot x=order y=grppct2 / name='grp2';
stepplot x=order y=grppct3 / name='grp3';
*/
/* Barchart is not OK, bottom 3 blockplots disappeared */

barchart x=order y=grppct1 / name='grp1';
barchart x=order y=grppct2 / name='grp2';
barchart x=order y=grppct3 / name='grp3';

endlayout;

blockplot x=order block=grptot1 / display=(values label)
valuehalign=right
repeatedvalues=true
valueattrs=(color=black style=italic size=9 family="Times New Roman")
label='Dummy A'
labelattrs=(color=black style=italic size=9 family="Times New Roman");
blockplot x=order block=grptot2 / display=(values label)
valuehalign=right
repeatedvalues=true
valueattrs=(color=black style=italic size=9 family="Times New Roman")
label='Dummy B'
labelattrs=(color=black style=italic size=9 family="Times New Roman");
blockplot x=order block=grptot3 / display=(values label)
valuehalign=right
repeatedvalues=true
valueattrs=(color=black style=italic size=9 family="Times New Roman")
label='Dummy C'
labelattrs=(color=black style=italic size=9 family="Times New Roman");

layout overlay;
entry halign=center 'Weeks';
endlayout;

sidebar / spacefill=false;
discretelegend 'grp1' 'grp2' 'grp3' / border=no across=3;
endsidebar;
endlayout;
endgraph;
end;
run;


ods graphics / width=8in height=6in imagename="&program";
proc sgrender data=&inds template=Gtl_Bars;
run;

%mend;

%BarPlot(inds=freqout,
title1=&test01,
title2=&analset,
ylabel=%str(Proportion of Subjects with HbA1c < 7% )
);
14 REPLIES 14
Cynthia_sas
SAS Super FREQ
Hi,
An < sign (or > sign) caused your posted code to be interpreted as HTML tags by the forum posting software -- so if you were wondering why your posting seemed to "disappear", that's why it happened.. So the solution is to "hide" the < sign in such as way that it will NOT be interpreted as HTML.

The way you hide the < sign in code is to use
&lt;
ampersand-L-T-semicolon

in any code you plan to post -- you can generally do this by doing a FIND/REPLACE in your text editor. In a similar fashion, any > sign would be replaced with &gt; in your code.

cynthia
CharlieHe
Fluorite | Level 6
layout lattice / rows=5 columndatarange=union rowweights=(0.84 .04 .04 .04 .04);
layout overlay / cycleattrs=true ;
/* Stepplot is OK */
/* stepplot x=order y=grppct1 / name='grp1';
stepplot x=order y=grppct2 / name='grp2';
stepplot x=order y=grppct3 / name='grp3';
*/
/* Barchart is not OK, bottom 3 blockplots disappeared */
barchart x=order y=grppct1 / name='grp1';
barchart x=order y=grppct2 / name='grp2';
barchart x=order y=grppct3 / name='grp3';
endlayout;

blockplot x=order block=grptot1 / display=(values label)
valuehalign=right
repeatedvalues=true
valueattrs=(color=black style=italic size=9 family="Times New Roman")
label='Dummy A'
labelattrs=(color=black style=italic size=9 family="Times New Roman");
blockplot x=order block=grptot2 / display=(values label)
valuehalign=right
repeatedvalues=true
valueattrs=(color=black style=italic size=9 family="Times New Roman")
label='Dummy B'
labelattrs=(color=black style=italic size=9 family="Times New Roman");
blockplot x=order block=grptot3 / display=(values label)
valuehalign=right
repeatedvalues=true
valueattrs=(color=black style=italic size=9 family="Times New Roman")
label='Dummy C'
labelattrs=(color=black style=italic size=9 family="Times New Roman");

layout overlay;
entry halign=center 'Weeks';
endlayout;

sidebar / spacefill=false;
discretelegend 'grp1' 'grp2' 'grp3' / border=no across=3;
endsidebar;
endlayout;
endgraph;
end;
run;

ods graphics / width=8in height=6in imagename="&program";
proc sgrender data=&inds template=Gtl_Bars;
run;
%mend;

%BarPlot(inds=freqout,
title1=&test01,
title2=&analset,
ylabel=%str(Proportion of Subjects with HbA1c < 7% ) );
CharlieHe
Fluorite | Level 6
Hi Cynthia,

Thanks. I do not have < or > in the code and not sure why the code was cut off. I have copied rest code in the reply post.

Thanks for you help.

Yeming

Here is the statement got cut off.
entryfootnote textattrs=(weight=normal size=8 family="Times New Roman") halign=left "Created on " SYSDATE;
Jay54
Meteorite | Level 14
I am still looking, but one reason is that each cell with its own axis will take up too much space. So, add the ColumnAxes - EndColumnAxes block to get a single common external axis.

Still, I had to add Layout Overlay around each BlockPlot. I don't know why, but at least this works. See attached code and graph. Let me know if this is what you expect. I had to un-macrofy your code to see what the errors were.
Cynthia_sas
SAS Super FREQ
Hmmm...well, in the code you've posted, it looks to me like you did have something that upset the forum mechanism.

cynthia

[pre]
ylabel=%str(Proportion of Subjects with HbA1c < 7% ) );
[/pre]
Jay54
Meteorite | Level 14
Yes, we have a reported defect with mixing of character and numeric data as I mentioned earlier. The work around is to make the X axis data for all plots as discrete (they will become discrete anyway once the defect is fixed). Or, put LAYOUT OVERLAY around each BLOCKPLOT and force the axis to DISCRETE as shown below. You also have to set some DISPLAY options to get the look you want.

layout overlay/xaxisopts=(type=discrete display=none) walldisplay=none;
CharlieHe
Fluorite | Level 6
Hi Sanjay,

Thanks for your reply. The graph now looks different.
The original stepplot is same as old SAS/Graph output. ie. the blockplot acts like annotation outside main plot (stepplot or barchart). I still wish we can have something like the stepplot.

Thanks,
Yeming
Jay54
Meteorite | Level 14
I believe it is the interaction between linear and discrete data between the Bar and the Block plot. StepPlot by default assumes interval data, just like block plots. So thay are all consistent.

But when you change the top plot to BarChart, that becomes the primary plot, and the axis is assumed to be discrete. Then, the block plot using the same numeric data cannot draw on the discrete axis. It should, but there may be a bug.

If you use a character X varialbe on all plots like the "Window", that works . Or, if you change "Order" to character, that will work too.
Jay54
Meteorite | Level 14
Note: Bar widths for the 2nd and 3rd bars are reduced so you can see all 3 bars. If you don't set barwidth, the bars will occlude the previous ones. Alternatively, you can also set discrete offset to set the bars side-by-side:

barchart x=window y=grppct1 / name='grp1' barwidth=0.2 discreteoffset=-0.2;
barchart x=window y=grppct2 / name='grp2' barwidth=0.2;
barchart x=window y=grppct3 / name='grp3' barwidth=0.2 discreteoffset=0.2;
CharlieHe
Fluorite | Level 6
Hi Sanjay and Cynthia,

Thank you both.

Using character variable "window" instead numeric "order" works. The work around also works good.

Sorry, Cynthia. I do not know why I missed that one. I guess I was thinking < and > in html context.

Thanks again.

Yeming
Jay54
Meteorite | Level 14
Just for my information...Did you go with overlaid bars (Proportion2) or side-by-side (Proportion3)?
CharlieHe
Fluorite | Level 6
Side by side. Here is my template and output looks good. If you have any suggestion, please let me know (I need the template for more 10 projects). - Thanks.

proc template;
define statgraph Gtl_Bars;
begingraph;
entrytitle halign=left "&title1";
entrytitle textattrs=(weight=normal size=9) halign=left "(&title2)";
entrytitle halign=left " ";
entryfootnote halign=left "Generated by &tabno..sas on &sysdate9";
layout lattice / rows=5 columndatarange=union rowweights=(0.84 .04 .04 .04 .04);
layout overlay / cycleattrs=true
yaxisopts=(label="&ylabel" offsetmin=0)
xaxisopts=(offsetmin=0.1 offsetmax=0.1 display=(line ticks tickvalues)
linearopts=(tickdisplaylist=('Baseline' 'Week 6' 'Week 12' 'Week 18' 'Week 26' 'Week 26 LOCF')));
barchart x=window y=grppct1 / discreteoffset=-0.2 barwidth=0.2 fillattrs=(color=lightgray) name='grp1';
barchart x=window y=grppct2 / discreteoffset= 0.0 barwidth=0.2 fillattrs=(color=darkgray) name='grp2';
barchart x=window y=grppct3 / discreteoffset= 0.2 barwidth=0.2 fillattrs=(color=gray) name='grp3';
endlayout;

layout overlay;
entry halign=center 'Weeks';
endlayout;

blockplot x=window block=grptot1 / display=(values label) valuehalign=right repeatedvalues=true
label='Dummy A' labelattrs=(color=black);
blockplot x=window block=grptot2 / display=(values label) valuehalign=right repeatedvalues=true
label='Dummy B' labelattrs=(color=black);
blockplot x=window block=grptot3 / display=(values label) valuehalign=right repeatedvalues=true
label='Dummy C' labelattrs=(color=black);
sidebar / spacefill=false;
discretelegend 'grp1' 'grp2' 'grp3' / border=no across=3;
endsidebar;
endlayout;
endgraph;
end;
run;
Jay54
Meteorite | Level 14
You are mostly there. If you really want gray scale colors, you can use style=journal on the ods listing destination for consistent colors. If the "Weeks" is really a axis label, you can leave it as is and get rid of the extra Entry statement
CharlieHe
Fluorite | Level 6
Hi Sanjay,

Thank you very much for your help. I will try new style.
For x-axis labeling, we will leave as is since it is requested by our medical team.

Kind regards,
Yeming

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 14 replies
  • 1917 views
  • 0 likes
  • 3 in conversation