<?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: Generate Two different Graphs in one PROC Template in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984466#M25852</link>
    <description>&lt;P&gt;Thank you very much.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Mar 2026 05:24:01 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2026-03-08T05:24:01Z</dc:date>
    <item>
      <title>Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983943#M25806</link>
      <description>&lt;P&gt;I am looking to generate a bargraph and line graphs with two axis using proc template. However I am having difficulty to get further. I really appreciate your help.&lt;/P&gt;
&lt;DIV id="tinyMceEditorSASuserlot_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditorSASuserlot_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;1. my barchart should starts from the x-axis, instead of line at Y=0&lt;/P&gt;
&lt;P&gt;2. want my scatter and Series plot should start from (0,0). I tried to control but not successful&lt;/P&gt;
&lt;P&gt;3. I want to duplicate the Score at each Month (Start from Month 1 to Month 12). and generate the same graph where we have two bars&amp;nbsp; at each months. Example, at Month 1 I have score 3, I need score 3 and score 6 bars..&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 902px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113330i322F46C79A7A0D4D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create the monthly_score dataset */
data monthly_score;
    length trtpn 8 visit $10 score 8 avg 8;
    
    call streaminit(123);
    
    do trtpn = 1 to 2;
        do month = 1 to 12;
            /* Create visit name */
            visit = cats('Month', month);
            score = floor(rand('uniform') * 6);
            avg = .;
            
            if month = 6 then do;
                if trtpn = 1 then avg = 3.5;
                else avg = 3.5 + (rand('uniform') - 0.5) * 0.4;
            end;
            else if month = 12 then do;
                if trtpn = 1 then avg = 6.8;
                else avg = 6.8 + (rand('uniform') - 0.5) * 0.4;
            end;
            
            if avg ne . then avg = round(avg, 0.1);
            
            output;
        end;
    end;
    
    drop month;
run;

/* Create dummy record for BL with avg=0 but score missing */
data dummy;
    visit = "BL";
    avg = 0;
    trtpn = 1;
    score = .;
run;

/* Create dataset with counts for trtpn=1 */
data monthly_score_trt1;
    set monthly_score dummy;
    where trtpn = 1;
run;

proc sort data = monthly_score_trt1;
    by trtpn visit;
run;

/* Create a format to display month names */
proc format;
    value visitfmt
        0 = " "
        1 = "Month1"
        2 = "Month2"
        3 = "Month3"
        4 = "Month4"
        5 = "Month5"
        6 = "Month6"
        7 = "Month7"
        8 = "Month8"
        9 = "Month9"
        10 = "Month10"
        11 = "Month11"
        12 = "Month12";
run;

/* Create dataset with numeric visit variable */
data bar_data;
    set monthly_score_trt1;
    by trtpn visit;
    
    if visit = "BL" then visit_num = 0;
    else visit_num = input(scan(visit, -1, 'Month'), 8.);
    
    bar_count = score;
    
    if visit = "BL" then bar_count = .;
    
    keep trtpn visit visit_num score avg bar_count;
run;

proc sort data=bar_data;
    by visit_num;
run;

ods path(prepend) work.templat(update);

/* Create template with dual y-axes */
proc template;
    define statgraph bargraph_trt1_dual;
        begingraph;
            entrytitle "Bar Graph by Visit for School Group 1";
            entrytitle "with Counts Displayed on Top";
            
            layout overlay / 
                xaxisopts=(
                    label="Visit"
                    type=linear
                    linearopts=(
                        viewmin=1 viewmax=12
                        tickvaluelist=(1 2 3 4 5 6 7 8 9 10 11 12)
                        tickvalueformat=visitfmt.
                    TICKVALUEFITPOLICY=rotate
                    TICKVALUEROTATION=DIAGONAL
                    TICKVALUEPRIORITY=true)
                )
                yaxisopts=(
                    label="Score Values"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=1)
                    )
                )
                y2axisopts=(
                    label="Average Score"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=.5)
                    )
                );
                
                barchart x=visit_num y=score /
                    fillattrs=(color=CX4A7DB4 transparency=0.2)
                    outlineattrs=(color=CX4A7DB4  thickness=1)
                    barwidth=0.6
                    name="bars"
                    legendlabel="Score Values"
                    includemissinggroup=false
                    yaxis=y
					;
                
                scatterplot x=visit_num y=score /
                    markerattrs=(symbol=square size=0)
                    datalabel=bar_count
                    datalabelposition=top
                    datalabelattrs=(
                        size=10pt 
                        weight=bold 
                        color=black
                    )
                    yaxis=y;
                
                scatterplot x=visit_num y=avg /
                    markerattrs=(
                        symbol=circlefilled 
                        size=8 
                        color=CXFF7F0E
                    )
                    name="avg"
                    legendlabel="Average Score (Month 6 &amp;amp; 12)"
                    yaxis=y2;
                
                seriesplot x=visit_num y=avg /
                    lineattrs=(
                        pattern=shortdash 
                        color=CXFF7F0E 
                        thickness=2
                    )
                    name="series"
                    legendlabel="Average Trend"
                    yaxis=y2;
                
                /* Reference line to mark start of months */
                *referenceline x=0.5 /
                    lineattrs=(pattern=solid color=lightgray thickness=1)
                    curvelabel="Baseline"
                    curvelabelposition=min;
                
                /* Legend */
                discretelegend "bars" "avg" "series" /
                    location=outside
                    halign=center
                    border=true
                    autoalign=(bottom);
            endlayout;
        endgraph;
		end;
    run;
    
/* Render the graph with dual axes */
proc sgrender data=bar_data template=bargraph_trt1_dual;
    format score 4.1 avg 4.1 visit_num visitfmt.;
    label score="Score Value" 
          avg="Average Score" 
          visit="Visit"
          bar_count="Count";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Feb 2026 05:46:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983943#M25806</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2026-02-24T05:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983947#M25807</link>
      <description>&lt;P&gt;You need to use option offsetmin=0 .&lt;/P&gt;
&lt;P&gt;And the third question I don't understand , you want to display two bars one by one ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;            layout overlay / 
                xaxisopts=(  &lt;STRONG&gt;OFFSETMIN=0&lt;/STRONG&gt;
                    label="Visit"
                    type=linear
                    linearopts=(
                        viewmin=1 viewmax=12
                        tickvaluelist=(1 2 3 4 5 6 7 8 9 10 11 12)
                        tickvalueformat=visitfmt.
                    TICKVALUEFITPOLICY=rotate
                    TICKVALUEROTATION=DIAGONAL
                    TICKVALUEPRIORITY=true)
                )
                yaxisopts=( &lt;STRONG&gt;OFFSETMIN=0&lt;/STRONG&gt;
                    label="Score Values"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=1)
                    )
                )
                y2axisopts=( &lt;STRONG&gt;OFFSETMIN=0&lt;/STRONG&gt;
                    label="Average Score"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=.5)
                    )
                );&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="屏幕截图 2025-09-09 175017.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113331iB7017283B17C5660/image-size/large?v=v2&amp;amp;px=999" role="button" title="屏幕截图 2025-09-09 175017.png" alt="屏幕截图 2025-09-09 175017.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Feb 2026 07:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983947#M25807</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-02-24T07:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983949#M25808</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-02-24 025230.png" style="width: 819px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113333i6250DAA060879A6E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-02-24 025230.png" alt="Screenshot 2026-02-24 025230.png" /&gt;&lt;/span&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes. Some thing like this. for every visit.&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorSASuserlot_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Feb 2026 08:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983949#M25808</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2026-02-24T08:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983952#M25809</link>
      <description>&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* Create the monthly_score dataset */
data monthly_score;
    length trtpn 8 visit $10 score 8 avg 8;
    
    call streaminit(123);
    
    do trtpn = 1 to 2;
        do month = 1 to 12;
            /* Create visit name */
            visit = cats('Month', month);
            score = floor(rand('uniform') * 6);
            avg = .;
            
            if month = 6 then do;
                if trtpn = 1 then avg = 3.5;
                else avg = 3.5 + (rand('uniform') - 0.5) * 0.4;
            end;
            else if month = 12 then do;
                if trtpn = 1 then avg = 6.8;
                else avg = 6.8 + (rand('uniform') - 0.5) * 0.4;
            end;
            
            if avg ne . then avg = round(avg, 0.1);
            
            output;
        end;
    end;
    
    drop month;
run;

/* Create dummy record for BL with avg=0 but score missing */
data dummy;
    visit = "BL";
    avg = 0;
    trtpn = 1;
    score = .;
run;

/* Create dataset with counts for trtpn=1 */
&lt;STRONG&gt;data monthly_score_trt1;
    set monthly_score dummy;
run;&lt;/STRONG&gt;

proc sort data = monthly_score_trt1;
    by trtpn visit;
run;

/* Create a format to display month names */
proc format;
    value visitfmt
        0 = " "
        1 = "Month1"
        2 = "Month2"
        3 = "Month3"
        4 = "Month4"
        5 = "Month5"
        6 = "Month6"
        7 = "Month7"
        8 = "Month8"
        9 = "Month9"
        10 = "Month10"
        11 = "Month11"
        12 = "Month12";
run;

/* Create dataset with numeric visit variable */
data bar_data;
    set monthly_score_trt1;
    by trtpn visit;
    
    if visit = "BL" then visit_num = 0;
    else visit_num = input(scan(visit, -1, 'Month'), 8.);
    
    bar_count = score;
    
    if visit = "BL" then bar_count = .;
    
    keep trtpn visit visit_num score avg bar_count;
run;

proc sort data=bar_data;
    by &lt;STRONG&gt;trtpn&lt;/STRONG&gt; visit_num;
run;

ods path(prepend) work.templat(update);

/* Create template with dual y-axes */
proc template;
    define statgraph bargraph_trt1_dual;
        begingraph;
            entrytitle "Bar Graph by Visit for School Group 1";
            entrytitle "with Counts Displayed on Top";
            
            layout overlay / 
                xaxisopts=(  &lt;STRONG&gt;OFFSETMIN=0&lt;/STRONG&gt;
                    label="Visit"
                    type=linear
                    linearopts=(
                        viewmin=1 viewmax=12
                        tickvaluelist=(1 2 3 4 5 6 7 8 9 10 11 12)
                        tickvalueformat=visitfmt.
                    TICKVALUEFITPOLICY=rotate
                    TICKVALUEROTATION=DIAGONAL
                    TICKVALUEPRIORITY=true)
                )
                yaxisopts=( &lt;STRONG&gt;OFFSETMIN=0&lt;/STRONG&gt;
                    label="Score Values"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=1)
                    )
                )
                y2axisopts=( &lt;STRONG&gt;OFFSETMIN=0&lt;/STRONG&gt;
                    label="Average Score"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=.5)
                    )
                );
                
                barchart x=visit_num y=score /
                    fillattrs=(color=CX4A7DB4 transparency=0.2)
                    outlineattrs=(color=CX4A7DB4  thickness=1)
                    barwidth=0.6
                    name="bars"
                    legendlabel="Score Values"
                    includemissinggroup=false
                    yaxis=y
					&lt;STRONG&gt;BARLABEL=on
					GROUP=trtpn
					GROUPDISPLAY=cluster&lt;/STRONG&gt;
					;
                
/*                scatterplot x=visit_num y=score /*/
/*                    markerattrs=(symbol=square size=0)*/
/*                    datalabel=bar_count*/
/*                    datalabelposition=top*/
/*                    datalabelattrs=(*/
/*                        size=10pt */
/*                        weight=bold */
/*                        color=black*/
/*                    )*/
/*                    yaxis=y;*/
                
                scatterplot x=visit_num y=avg /
                    markerattrs=(
                        symbol=circlefilled 
                        size=8 
                        color=CXFF7F0E
                    )
                    name="avg"
                    legendlabel="Average Score (Month 6 &amp;amp; 12)"
                    yaxis=y2;
                
                seriesplot x=visit_num y=avg /
                    lineattrs=(
                        pattern=shortdash 
                        color=CXFF7F0E 
                        thickness=2
                    )
                    name="series"
                    legendlabel="Average Trend"
                    yaxis=y2;
                
                /* Reference line to mark start of months */
                *referenceline x=0.5 /
                    lineattrs=(pattern=solid color=lightgray thickness=1)
                    curvelabel="Baseline"
                    curvelabelposition=min;
                
                /* Legend */
                discretelegend "bars" "avg" "series" /
                    location=outside
                    halign=center
                    border=true
                    autoalign=(bottom);
            endlayout;
        endgraph;
		end;
    run;
    
/* Render the graph with dual axes */
proc sgrender data=bar_data  template=bargraph_trt1_dual;
    format &lt;STRONG&gt;score 4.0&lt;/STRONG&gt; avg 4.1 visit_num visitfmt.;
    label score="Score Value" 
          avg="Average Score" 
          visit="Visit"
          bar_count="Count";
run;&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorKsharp_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="屏幕截图 2025-09-09 175017.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113334iB08A39E0C86579B9/image-size/large?v=v2&amp;amp;px=999" role="button" title="屏幕截图 2025-09-09 175017.png" alt="屏幕截图 2025-09-09 175017.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Feb 2026 08:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983952#M25809</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-02-24T08:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983954#M25810</link>
      <description>&lt;P&gt;If you need to display these two bar with two different color:&lt;/P&gt;
&lt;PRE&gt;/* Create the monthly_score dataset */
data monthly_score;
    length trtpn 8 visit $10 score 8 avg 8;
    
    call streaminit(123);
    
    do trtpn = 1 to 2;
        do month = 1 to 12;
            /* Create visit name */
            visit = cats('Month', month);
            score = floor(rand('uniform') * 6);
            avg = .;
            
            if month = 6 then do;
                if trtpn = 1 then avg = 3.5;
                else avg = 3.5 + (rand('uniform') - 0.5) * 0.4;
            end;
            else if month = 12 then do;
                if trtpn = 1 then avg = 6.8;
                else avg = 6.8 + (rand('uniform') - 0.5) * 0.4;
            end;
            
            if avg ne . then avg = round(avg, 0.1);
            
            output;
        end;
    end;
    
    drop month;
run;

/* Create dummy record for BL with avg=0 but score missing */
data dummy;
    visit = "BL";
    avg = 0;
    trtpn = 1;
    score = .;
run;

/* Create dataset with counts for trtpn=1 */
data monthly_score_trt1;
    set monthly_score dummy;
	&lt;STRONG&gt;if trtpn=2 then call missing(avg);&lt;/STRONG&gt;
run;

proc sort data = monthly_score_trt1;
    by trtpn visit;
run;

/* Create a format to display month names */
proc format;
    value visitfmt
        0 = " "
        1 = "Month1"
        2 = "Month2"
        3 = "Month3"
        4 = "Month4"
        5 = "Month5"
        6 = "Month6"
        7 = "Month7"
        8 = "Month8"
        9 = "Month9"
        10 = "Month10"
        11 = "Month11"
        12 = "Month12";
run;

/* Create dataset with numeric visit variable */
data bar_data;
    set monthly_score_trt1;
    by trtpn visit;
    
    if visit = "BL" then visit_num = 0;
    else visit_num = input(scan(visit, -1, 'Month'), 8.);
    
    bar_count = score;
    
    if visit = "BL" then bar_count = .;
    
    keep trtpn visit visit_num score avg bar_count;
run;

proc sort data=bar_data;
    by trtpn visit_num;
run;

ods path(prepend) work.templat(update);

/* Create template with dual y-axes */
proc template;
    define statgraph bargraph_trt1_dual;
        begingraph;
            entrytitle "Bar Graph by Visit for School Group 1";
            entrytitle "with Counts Displayed on Top";
            
            layout overlay / 
                xaxisopts=(  OFFSETMIN=0
                    label="Visit"
                    type=linear
                    linearopts=(
                        viewmin=1 viewmax=12
                        tickvaluelist=(1 2 3 4 5 6 7 8 9 10 11 12)
                        tickvalueformat=visitfmt.
                    TICKVALUEFITPOLICY=rotate
                    TICKVALUEROTATION=DIAGONAL
                    TICKVALUEPRIORITY=true)
                )
                yaxisopts=( OFFSETMIN=0
                    label="Score Values"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=1)
                    )
                )
                y2axisopts=( OFFSETMIN=0
                    label="Average Score"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=.5)
                    )
                );
                
                barchart x=visit_num y=score /
&lt;STRONG&gt;/*                    fillattrs=(color=CX4A7DB4 transparency=0.2)*/&lt;/STRONG&gt;
                    outlineattrs=(color=CX4A7DB4  thickness=1)
                    barwidth=0.6
                    name="bars"
                    legendlabel="Score Values"
                    includemissinggroup=false
                    yaxis=y
					BARLABEL=on
					GROUP=trtpn
					GROUPDISPLAY=cluster
					&lt;STRONG&gt;OUTLINEATTRS=(thickness=0)&lt;/STRONG&gt;
					;
                
/*                scatterplot x=visit_num y=score /*/
/*                    markerattrs=(symbol=square size=0)*/
/*                    datalabel=bar_count*/
/*                    datalabelposition=top*/
/*                    datalabelattrs=(*/
/*                        size=10pt */
/*                        weight=bold */
/*                        color=black*/
/*                    )*/
/*                    yaxis=y;*/
                
                scatterplot x=visit_num y=avg /
                    markerattrs=(
                        symbol=circlefilled 
                        size=8 
                        color=CXFF7F0E
                    )
                    name="avg"
                    legendlabel="Average Score (Month 6 &amp;amp; 12)"
                    yaxis=y2;
                
                seriesplot x=visit_num y=avg /
                    lineattrs=(
                        pattern=shortdash 
                        color=CXFF7F0E 
                        thickness=2
                    )
                    name="series"
                    legendlabel="Average Trend"
                    yaxis=y2;
                
                /* Reference line to mark start of months */
                *referenceline x=0.5 /
                    lineattrs=(pattern=solid color=lightgray thickness=1)
                    curvelabel="Baseline"
                    curvelabelposition=min;
                
                /* Legend */
                discretelegend "bars" "avg" "series" /
                    location=outside
                    halign=center
                    border=true
                    autoalign=(bottom);
            endlayout;
        endgraph;
		end;
    run;
    
/* Render the graph with dual axes */
proc sgrender data=bar_data  template=bargraph_trt1_dual;
    format score 4.0 avg 4.1 visit_num visitfmt.;
    label score="Score Value" 
          avg="Average Score" 
          visit="Visit"
          bar_count="Count";
run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="屏幕截图 2025-09-09 175017.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113335i4F8A5DE3C7B19782/image-size/large?v=v2&amp;amp;px=999" role="button" title="屏幕截图 2025-09-09 175017.png" alt="屏幕截图 2025-09-09 175017.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Feb 2026 08:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983954#M25810</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-02-24T08:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983963#M25811</link>
      <description>Thank you very much. I Really appreciate your help.   Got a question, when I do why the " double score" bar coming first. Is there any way I can order the regular score first and double score second. Also the extra line graph is it becaz the avg value retained ( if it's the case I can adjust it manually by making it missing)</description>
      <pubDate>Tue, 24 Feb 2026 14:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/983963#M25811</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2026-02-24T14:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984006#M25824</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;why the " double score" bar coming first"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I don't understand what " double score" is . Do you want to display 2 before 1 ? Just reorder it .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=bar_data;
    by &lt;STRONG&gt;descending&lt;/STRONG&gt; trtpn visit_num;
run;&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorKsharp_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;Also the extra line graph is it becaz the avg value retained"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes. I already set it missing in my code.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data monthly_score_trt1;
    set monthly_score dummy;
	&lt;STRONG&gt;if trtpn=2 then call missing(avg);&lt;/STRONG&gt;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Feb 2026 06:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984006#M25824</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-02-25T06:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984252#M25846</link>
      <description>&lt;P&gt;Thank you for the solution.&amp;nbsp; Apologies, Error on my part that the treatments were assigned in reverse. Got fixed. thanks again.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2026 05:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984252#M25846</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2026-03-01T05:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984432#M25848</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Is there a way I can add the back group after Month 3 in the graph?. I&amp;nbsp; was able to get the background, but don't know how to start from a specific value on- x-axis&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2026 19:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984432#M25848</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2026-03-06T19:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984447#M25850</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;&amp;nbsp;I can add the&lt;STRONG&gt; back group&lt;/STRONG&gt; after Month 3"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you mean background ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here is the code you can start with.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;/* Create the monthly_score dataset */
data monthly_score;
    length trtpn 8 visit $10 score 8 avg 8;
    
    call streaminit(123);
    
    do trtpn = 1 to 2;
        do month = 1 to 12;
            /* Create visit name */
            visit = cats('Month', month);
            score = floor(rand('uniform') * 6);
            avg = .;
            
            if month = 6 then do;
                if trtpn = 1 then avg = 3.5;
                else avg = 3.5 + (rand('uniform') - 0.5) * 0.4;
            end;
            else if month = 12 then do;
                if trtpn = 1 then avg = 6.8;
                else avg = 6.8 + (rand('uniform') - 0.5) * 0.4;
            end;
            
            if avg ne . then avg = round(avg, 0.1);
            
            output;
        end;
    end;
    
    drop month;
run;

/* Create dummy record for BL with avg=0 but score missing */
data dummy;
    visit = "BL";
    avg = 0;
    trtpn = 1;
    score = .;
run;

/* Create dataset with counts for trtpn=1 */
data monthly_score_trt1;
    set monthly_score dummy;
	if trtpn=2 then call missing(avg);
run;

proc sort data = monthly_score_trt1;
    by trtpn visit;
run;

/* Create a format to display month names */
proc format;
    value visitfmt
        0 = " "
        1 = "Month1"
        2 = "Month2"
        3 = "Month3"
        4 = "Month4"
        5 = "Month5"
        6 = "Month6"
        7 = "Month7"
        8 = "Month8"
        9 = "Month9"
        10 = "Month10"
        11 = "Month11"
        12 = "Month12";
run;

/* Create dataset with numeric visit variable */
data bar_data;
    set monthly_score_trt1;
    by trtpn visit;
    
    if visit = "BL" then visit_num = 0;
    else visit_num = input(scan(visit, -1, 'Month'), 8.);
    
    bar_count = score;
    
    if visit = "BL" then bar_count = .;
	&lt;STRONG&gt;max=ifn(trtpn=2 and visit_num&amp;gt;3,7,.);  /*7 is the max value in Y axis*/&lt;/STRONG&gt;
    keep trtpn visit visit_num score avg bar_count  &lt;STRONG&gt;max&lt;/STRONG&gt;;
run;

proc sort data=bar_data;
    by trtpn visit_num;
run;

ods path(prepend) work.templat(update);

/* Create template with dual y-axes */
proc template;
    define statgraph bargraph_trt1_dual;
        begingraph;
            entrytitle "Bar Graph by Visit for School Group 1";
            entrytitle "with Counts Displayed on Top";
            
            layout overlay / 
                xaxisopts=(  OFFSETMIN=0
                    label="Visit"
                    type=linear
                    linearopts=(
                        viewmin=1 viewmax=12
                        tickvaluelist=(1 2 3 4 5 6 7 8 9 10 11 12)
                        tickvalueformat=visitfmt.
                    TICKVALUEFITPOLICY=rotate
                    TICKVALUEROTATION=DIAGONAL
                    TICKVALUEPRIORITY=true)
                )
                yaxisopts=( OFFSETMIN=0 &lt;STRONG&gt;OFFSETMAX=0&lt;/STRONG&gt;
                    label="Score Values"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=1)
                    )
                )
                y2axisopts=( OFFSETMIN=0 &lt;STRONG&gt;OFFSETMAX=0&lt;/STRONG&gt;
                    label="Average Score"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=.5)
                    )
                );



                &lt;STRONG&gt;
              barchart x=visit_num y=max /
                    barwidth=1
                    name="other_bars"
                    yaxis=y
					OUTLINEATTRS=(thickness=0)
					DATATRANSPARENCY=0.6
					;&lt;/STRONG&gt;





                barchart x=visit_num y=score /
/*                    fillattrs=(color=CX4A7DB4 transparency=0.2)*/
                    outlineattrs=(color=CX4A7DB4  thickness=1)
                    barwidth=0.6
                    name="bars"
                    legendlabel="Score Values"
                    includemissinggroup=false
                    yaxis=y
					BARLABEL=on
					GROUP=trtpn
					GROUPDISPLAY=cluster
					OUTLINEATTRS=(thickness=0)
					;
                
/*                scatterplot x=visit_num y=score /*/
/*                    markerattrs=(symbol=square size=0)*/
/*                    datalabel=bar_count*/
/*                    datalabelposition=top*/
/*                    datalabelattrs=(*/
/*                        size=10pt */
/*                        weight=bold */
/*                        color=black*/
/*                    )*/
/*                    yaxis=y;*/
                
                scatterplot x=visit_num y=avg /
                    markerattrs=(
                        symbol=circlefilled 
                        size=8 
                        color=CXFF7F0E
                    )
                    name="avg"
                    legendlabel="Average Score (Month 6 &amp;amp; 12)"
                    yaxis=y2;
                
                seriesplot x=visit_num y=avg /
                    lineattrs=(
                        pattern=shortdash 
                        color=CXFF7F0E 
                        thickness=2
                    )
                    name="series"
                    legendlabel="Average Trend"
                    yaxis=y2;





 
                /* Reference line to mark start of months */
                *referenceline x=0.5 /
                    lineattrs=(pattern=solid color=lightgray thickness=1)
                    curvelabel="Baseline"
                    curvelabelposition=min;
                
                /* Legend */
                discretelegend "bars" "avg" "series" /
                    location=outside
                    halign=center
                    border=true
                    autoalign=(bottom);
            endlayout;
        endgraph;
		end;
    run;
    
/* Render the graph with dual axes */
proc sgrender data=bar_data  template=bargraph_trt1_dual;
    format score 4.0 avg 4.1 visit_num visitfmt.;
    label score="Score Value" 
          avg="Average Score" 
          visit="Visit"
          bar_count="Count";
run;&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorKsharp_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="屏幕截图 2026-03-07 155045.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113473i93566CC82D97F295/image-size/large?v=v2&amp;amp;px=999" role="button" title="屏幕截图 2026-03-07 155045.png" alt="屏幕截图 2026-03-07 155045.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2026 07:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984447#M25850</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-03-07T07:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984454#M25851</link>
      <description>&lt;P&gt;An alternative way is using REFLINE statement.&lt;/P&gt;
&lt;PRE&gt;/* Create template with dual y-axes */
proc template;
    define statgraph bargraph_trt1_dual;
        begingraph;
            entrytitle "Bar Graph by Visit for School Group 1";
            entrytitle "with Counts Displayed on Top";
            
            layout overlay / 
                xaxisopts=(  OFFSETMIN=0 
                    label="Visit"
                    type=linear
                    linearopts=(
                        viewmin=1 viewmax=12
                        tickvaluelist=(1 2 3 4 5 6 7 8 9 10 11 12)
                        tickvalueformat=visitfmt.
                    TICKVALUEFITPOLICY=rotate
                    TICKVALUEROTATION=DIAGONAL
                    TICKVALUEPRIORITY=true)
                )
                yaxisopts=( OFFSETMIN=0 OFFSETMAX=0
                    label="Score Values"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=1)
                    )
                )
                y2axisopts=( OFFSETMIN=0 OFFSETMAX=0
                    label="Average Score"
                    linearopts=(
                        viewmin=0 viewmax=7
                        tickvaluesequence=(start=0 end=7 increment=.5)
                    )
                );
&lt;STRONG&gt;
REFERENCELINE X=4/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=5/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=6/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=7/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=8/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=9/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=10/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=11/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
REFERENCELINE X=12/lineattrs=(thickness=40) DATATRANSPARENCY=0.8 ;
&lt;/STRONG&gt;

                barchart x=visit_num y=score /
/*                    fillattrs=(color=CX4A7DB4 transparency=0.2)*/
                    outlineattrs=(color=CX4A7DB4  thickness=1)
                    barwidth=0.6
                    name="bars"
                    legendlabel="Score Values"
                    includemissinggroup=false
                    yaxis=y
					BARLABEL=on
					GROUP=trtpn
					GROUPDISPLAY=cluster
					OUTLINEATTRS=(thickness=0)
					;
                
/*                scatterplot x=visit_num y=score /*/
/*                    markerattrs=(symbol=square size=0)*/
/*                    datalabel=bar_count*/
/*                    datalabelposition=top*/
/*                    datalabelattrs=(*/
/*                        size=10pt */
/*                        weight=bold */
/*                        color=black*/
/*                    )*/
/*                    yaxis=y;*/
                
                scatterplot x=visit_num y=avg /
                    markerattrs=(
                        symbol=circlefilled 
                        size=8 
                        color=CXFF7F0E
                    )
                    name="avg"
                    legendlabel="Average Score (Month 6 &amp;amp; 12)"
                    yaxis=y2;
                
                seriesplot x=visit_num y=avg /
                    lineattrs=(
                        pattern=shortdash 
                        color=CXFF7F0E 
                        thickness=2
                    )
                    name="series"
                    legendlabel="Average Trend"
                    yaxis=y2;





 
                /* Reference line to mark start of months */
                *referenceline x=0.5 /
                    lineattrs=(pattern=solid color=lightgray thickness=1)
                    curvelabel="Baseline"
                    curvelabelposition=min;
                
                /* Legend */
                discretelegend "bars" "avg" "series" /
                    location=outside
                    halign=center
                    border=true
                    autoalign=(bottom);
            endlayout;
        endgraph;
		end;
    run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="屏幕截图 2026-03-07 170214.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113475iF090F5AC8CBD531A/image-size/large?v=v2&amp;amp;px=999" role="button" title="屏幕截图 2026-03-07 170214.png" alt="屏幕截图 2026-03-07 170214.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2026 08:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984454#M25851</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-03-07T08:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Two different Graphs in one PROC Template</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984466#M25852</link>
      <description>&lt;P&gt;Thank you very much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2026 05:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Generate-Two-different-Graphs-in-one-PROC-Template/m-p/984466#M25852</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2026-03-08T05:24:01Z</dc:date>
    </item>
  </channel>
</rss>

