<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476632#M16463</link>
    <description>&lt;P&gt;Nifty, thank you! I will work with this.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jul 2018 22:51:11 GMT</pubDate>
    <dc:creator>bstarr</dc:creator>
    <dc:date>2018-07-09T22:51:11Z</dc:date>
    <item>
      <title>PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476509#M16452</link>
      <description>&lt;P&gt;Hello SAS experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create some plots with annotations using PROC TEMPLATE. Currently, I have the annotations set up using an annotation dataset (rather than incorporating the annotations into the PROC TEMPLATE procedure itself using statements such as drawtext). I am getting it close to working correctly, but the annotations are appearing for all BY groups in each plot. That is, BY group=1 shows annotations for all BY groups, even though I have the BY group variable in the annotations dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way I can have the annotations show only for each corresponding BY group? Sample code to reproduce my plot is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data graphdata;
input rpt_strat $ est delta level CI;
format Est CI percentn11.2;

datalines;
20-to-44 -.0383 -0.002374357 0.05 -.0572
20-to-44 . -0.002374357 0.05 -.0195
45-to-64 -.0317 -0.004262066 0.05 -.0525
45-to-64 . -0.004262066 0.05 -.0109
;
run;
ods path(prepend) Work.Templat(update);
%SGANNO;

data anno;
set graphdata;
    if Est ~= .;
    %SGTEXT(label="Estimate", x1=Est, y1=75, x1space='datavalue', y1space='graphpercent', anchor='center',width=200, widthunit='pixel');
    keep rpt_strat;
run;

proc template;
    define statgraph CIPlot;
        begingraph / designwidth=800px designheight=200px;
            layout overlay / yaxisOpts=(display=none)
                             xAxisOpts=(label="Rate");
                annotate;
                scatterplot x=Est y=level / markerattrs=(symbol=circlefilled size=10) datalabel=Est datalabelposition=top;
                seriesplot  x=CI y =level / display=(markers) markerattrs=(symbol=ibeam size=10) datalabel=CI datalabelposition=top;
                referenceline x=delta   / lineattrs=(pattern=2);
                referenceline x=0       / lineattrs=(pattern=1);
            endlayout;
        endgraph;
    end;
run;

proc sgrender data=graphdata template=CIPlot sganno=anno;
by rpt_strat;
title1 "Non-inferiority Confidence Interval for Measure";
title2 "Ages #byval1";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that "Estimate" is being displayed twice on each graph: it should only be displayed once per graph, above the big blue dot. Is there a way to fix this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, if anyone knows how to suppress the automatic BY group heading "rpt_strat=20-to-44" and "rpt_strat=45-to-64" I'd appreciate that too!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS 9.4 TS1M5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Brian&lt;/P&gt;&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 09 Jul 2018 16:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476509#M16452</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2018-07-09T16:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476609#M16460</link>
      <description>&lt;P&gt;The behavior is as expected: EACH plot will plot the entire Annotate set, or at least the bits that would fit within the plot area.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest adding another variable&amp;nbsp;and using&amp;nbsp;a TEXTPLOT statement with the text and desired positions to match the by variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not aware of another way to get annotate sets to match on by variables only.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 20:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476609#M16460</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-09T20:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476623#M16461</link>
      <description>&lt;P&gt;Thank you, I was afraid of that. I will populate the annotations within PROC TEMPLATE itself.&amp;nbsp;I get that's how it works, but it seems like it&amp;nbsp;&lt;EM&gt;should&lt;/EM&gt; work in a way that the annotation is done separately for each BY group. Just one of those things, I suppose! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 21:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476623#M16461</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2018-07-09T21:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476626#M16462</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174733"&gt;@bstarr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, I was afraid of that. I will populate the annotations within PROC TEMPLATE itself.&amp;nbsp;I get that's how it works, but it seems like it&amp;nbsp;&lt;EM&gt;should&lt;/EM&gt; work in a way that the annotation is done separately for each BY group. Just one of those things, I suppose! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Something else: a better label variable, use the splitchar options.&lt;/P&gt;
&lt;PRE&gt;data graphdata;
infile datalines missover;
input rpt_strat $ est delta level CI ;
format Est CI percentn11.2;
if est ~= . then do;
   Text=catx('*',"Estimate",put(est,percentn11.2));
end;


datalines;
20-to-44 -.0383 -0.002374357 0.05 -.0572
20-to-44 . -0.002374357 0.05 -.0195
45-to-64 -.0317 -0.004262066 0.05 -.0525
45-to-64 . -0.004262066 0.05 -.0109
;
run;

proc template;
    define statgraph CIPlot;
        begingraph / designwidth=800px designheight=200px;
            layout overlay / yaxisOpts=(display=none)
                             xAxisOpts=(label="Rate");
                annotate;
                scatterplot x=Est y=level / markerattrs=(symbol=circlefilled size=10) 
                                           datalabel=text 
                                           DATALABELSPLIT=TRUE 
                                           datalabelsplitchar='*' 
                                           datalabelposition=top;
                seriesplot  x=CI y =level / display=(markers) markerattrs=(symbol=ibeam size=10) datalabel=CI datalabelposition=top;
                referenceline x=delta   / lineattrs=(pattern=2);
                referenceline x=0       / lineattrs=(pattern=1);
            endlayout;
        endgraph;
    end;
run;

proc sgrender data=graphdata template=CIPlot ;
by rpt_strat;
title1 "Non-inferiority Confidence Interval for Measure";
title2 "Ages #byval1";
run;title;&lt;/PRE&gt;
&lt;P&gt;You can set some datalabelattrs to change text to some extent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 22:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476626#M16462</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-09T22:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476632#M16463</link>
      <description>&lt;P&gt;Nifty, thank you! I will work with this.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 22:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476632#M16463</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2018-07-09T22:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476915#M16472</link>
      <description>&lt;P&gt;Another way is to use&amp;nbsp;the ID column in your Anno data set to subset your annotate observations. In this case, the ID column value would be the same as the rpt_strat column. To create the ID column, add parameter id=rpt_strat to the %SGTEXT macro call in your Anno DATA step:&lt;/P&gt;
&lt;PRE&gt;data anno;
set graphdata;
    if Est ~= .;
    %SGTEXT(id=rpt_strat, label="Estimate", x1=Est, y1=75, x1space='datavalue', y1space='graphpercent', anchor='center',width=200, widthunit='pixel');
    keep rpt_strat;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your CIPlot template code, to get the BY-Group variable value into your template, create dynamic variable _BYVAL_, and then in your ANNOTATE statement, add option ID = _BYVAL_:&lt;/P&gt;
&lt;PRE&gt;proc template;
    define statgraph CIPlot;
        dynamic _BYVAL_;
        begingraph / designwidth=800px designheight=200px;
            layout overlay / yaxisOpts=(display=none)
                             xAxisOpts=(label="Rate");
                annotate / id=_BYVAL_;
                scatterplot x=Est y=level / markerattrs=(symbol=circlefilled size=10) datalabel=Est datalabelposition=top;
                seriesplot  x=CI y =level / display=(markers) markerattrs=(symbol=ibeam size=10) datalabel=CI datalabelposition=top;
                referenceline x=delta   / lineattrs=(pattern=2);
                referenceline x=0       / lineattrs=(pattern=1);
            endlayout;
        endgraph;
    end;
run;&lt;/PRE&gt;
&lt;P&gt;Finally, to suppress the automatic BY-line, specify system option NOBYLINE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;options nobyline;
proc sgrender data=graphdata template=CIPlot sganno=anno;
by rpt_strat;
title1 "Non-inferiority Confidence Interval for Measure";
title2 "Ages #byval1";
run;
options byline; /* Restore BY-line */&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find information about subsetting annotate observations in&amp;nbsp;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=grstatug&amp;amp;docsetTarget=n0li1urcrpjzazn13cvye4kxnf3n.htm" target="_self"&gt;Subsetting Annotations&lt;/A&gt;&amp;nbsp;in &lt;EM&gt;SAS Graph Template Language: User’s Guide&lt;/EM&gt;. Hope this helps.&lt;/P&gt;
&lt;P&gt;&lt;!-- end ngIf: getDocset() --&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 19:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476915#M16472</guid>
      <dc:creator>sdengland</dc:creator>
      <dc:date>2018-07-10T19:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476952#M16476</link>
      <description>&lt;P&gt;Thank you, Steve. This is excellent! Does just what I need and still uses the annotation dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 21:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/476952#M16476</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2018-07-10T21:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/477043#M16480</link>
      <description>&lt;P&gt;I had never seen or thought of Steve's trick.&amp;nbsp; Very nice!&amp;nbsp; Inspired by it, I will write a blog for graphically speaking (&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/" target="_blank"&gt;https://blogs.sas.com/content/graphicallyspeaking/&lt;/A&gt;) in the next few days that shows how to specify the graph syntax in PROC SGPLOT with a BY statement, slightly post-process the template, then create the graphs with custom SG annotations for each BY group.&amp;nbsp; The latter part is based on my multiple blogs and papers on highly customized graphs.&amp;nbsp; Here is a preview of the code (again, giving credit to Steve for the idea of adding an ID variable that matches the BY variable).&amp;nbsp; I'll explore other ways too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=c;
   by sex;
run;

data anno;
   x1 = 20; y1 = 85; function = 'Text'; dataspace = 'GraphPercent'; width = 100;
   label = 'Female Students'; id = 'F'; output;
   label = 'Male Students';   id = 'M'; output;
run;

proc sgplot data=c tmplout='tmp.tmp';
   ods exclude sgplot;
   scatter y=weight x=height;
   by sex;
run;

data _null_;
   infile 'tmp.tmp';
   input;
   _infile_ = tranwrd(_infile_, 'sgplot;', 'by;');
   if _n_ eq 1 then call execute('proc template;');
   call execute(_infile_);
   if find(_infile_, 'layout overlay') then 
      call execute('dynamic _byval_; annotate / id=_byval_;');
run;      

ods html body='b.html';
title;
options nobyline;
proc sgrender data=c template=by sganno=anno; by sex; run;
options byline;
ods html close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jul 2018 12:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/477043#M16480</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2018-07-11T12:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TEMPLATE Annotation with BY Groups Not Working as Expected</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/477683#M16497</link>
      <description>&lt;P&gt;Excellent, I'm glad this sparked some interest! Thank you for sharing the code sample and I look forward to reading the blog post!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 20:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-TEMPLATE-Annotation-with-BY-Groups-Not-Working-as-Expected/m-p/477683#M16497</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2018-07-12T20:50:04Z</dc:date>
    </item>
  </channel>
</rss>

