<?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: Graph Recreation in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962586#M25378</link>
    <description>&lt;P&gt;Not completely sure I understand what you're trying to achieve - partly because the way you've described the variable "subgroupSuffix" does not match how you've coded it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* if you have subgroup='A-34B' ... ;
subgroupSuffix=scan(subgroup,-1,'-');
**... will yield '34B', not 'B' as you've indicated in your comment ;&lt;BR /&gt;**&amp;nbsp;if&amp;nbsp;you&amp;nbsp;really&amp;nbsp;want&amp;nbsp;the&amp;nbsp;last&amp;nbsp;character,&amp;nbsp;do&amp;nbsp;this:&amp;nbsp;;&lt;BR /&gt;subgroupSuffix=substr(subgroup,length(subgroup));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, just FYI, you can shorten your code substantially (skipping all the proc means, sorting and extra data steps by doing something like this immediately below your input data step (though use CROSS JOIN with caution):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table incidence_plot as
select a.*, scan(a.subgroup,-1,'-') as subgroupSuffix, b.groupavg, c.overallavg
from
	incidence A
	inner join
	(select group, mean(cumulativeincidence) as groupavg from incidence group by group) B
	on a.group=b.group
	cross join
	(select mean(cumulativeincidence) as overallavg from incidence) C
order by group, subgroup;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It seems like you are just trying to show, within each group (A-D), the group average.&amp;nbsp; I don't see an easy way to do what you're trying to do except to create a separate subgroup within each group for which the value is the group average.&amp;nbsp; &amp;nbsp;This will simply create an additional bar for each group - however, it won't match the Excel version visually.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Mar 2025 13:27:29 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2025-03-25T13:27:29Z</dc:date>
    <item>
      <title>Graph Recreation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962583#M25377</link>
      <description>&lt;P&gt;I am in the process of recreating the graph below, which was originally created in Excel, using SAS. The graph appears as follows:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="luvscandy27_0-1742904940966.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105618i3EAEFB3B35A19193/image-size/medium?v=v2&amp;amp;px=400" role="button" title="luvscandy27_0-1742904940966.png" alt="luvscandy27_0-1742904940966.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In SAS Studio, I am encountering the following error: "ERROR: The same group variable must be used for summarized plots." Any assistance in resolving this issue would be greatly appreciated. Code and data are as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* Sample Data */&lt;BR /&gt;data incidence;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input Group $ Subgroup $ CumulativeIncidence;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;A 1-34A 0.54&lt;BR /&gt;A 1-34B 0.42&lt;BR /&gt;A 1-34C 0.46&lt;BR /&gt;A 1-34D 0.42&lt;BR /&gt;A 1-34E 0.37&lt;BR /&gt;B 3-34B 0.39&lt;BR /&gt;B 3-34C 0.35&lt;BR /&gt;B 3-34D 0.43&lt;BR /&gt;B 3-34E 0.48&lt;BR /&gt;C 3-39A 0.45&lt;BR /&gt;C 3-39B 0.44&lt;BR /&gt;C 3-39C 0.50&lt;BR /&gt;C 3-39D 0.41&lt;BR /&gt;C 3-39E 0.35&lt;BR /&gt;D 4-39A 0.20&lt;BR /&gt;D 4-39B 0.28&lt;BR /&gt;D 4-39C 0.29&lt;BR /&gt;D 4-39D 0.24&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Extract subgroup suffix for consistent coloring */&lt;BR /&gt;data incidence;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set incidence;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SubgroupSuffix = scan(Subgroup, -1, '-'); /* Extract last part (e.g., A, B, C) */&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Compute Group and Overall Averages */&lt;BR /&gt;proc means data=incidence noprint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by Group;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var CumulativeIncidence;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output out=group_avg mean=GroupAvg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=incidence noprint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var CumulativeIncidence;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output out=overall_avg mean=OverallAvg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Add Overall Average to Each Row */&lt;BR /&gt;data overall_avg;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_ = 1 then set overall_avg;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set incidence;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Merge Group Average with the Data */&lt;BR /&gt;proc sort data=incidence; by Group; run;&lt;BR /&gt;proc sort data=group_avg; by Group; run;&lt;BR /&gt;&lt;BR /&gt;data incidence_plot;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge incidence group_avg overall_avg;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by Group;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format GroupAvg 10.2 OverallAvg 10.2;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Create the Plot */&lt;BR /&gt;proc sgplot data=incidence_plot;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; vbar Group / response=CumulativeIncidence &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group=SubgroupSuffix /* Color by subgroup suffix */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; groupdisplay=cluster &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalabel /* Show values above bars */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalabelattrs=(size=10);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; vline Group / response=GroupAvg &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;group=Group /* Use Group to plot the average correctly */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lineattrs=(thickness=2 color=red) &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; markers; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; refline OverallAvg / axis=y lineattrs=(thickness=2 color=blue pattern=shortdash);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xaxis discreteorder=data label="Groups";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; yaxis label="Cumulative Incidence";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keylegend / title="Subgroup (Color Key)" noborder;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; title "Cumulative Incidence by Group with Averages";&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2025 12:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962583#M25377</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2025-03-25T12:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Graph Recreation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962586#M25378</link>
      <description>&lt;P&gt;Not completely sure I understand what you're trying to achieve - partly because the way you've described the variable "subgroupSuffix" does not match how you've coded it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* if you have subgroup='A-34B' ... ;
subgroupSuffix=scan(subgroup,-1,'-');
**... will yield '34B', not 'B' as you've indicated in your comment ;&lt;BR /&gt;**&amp;nbsp;if&amp;nbsp;you&amp;nbsp;really&amp;nbsp;want&amp;nbsp;the&amp;nbsp;last&amp;nbsp;character,&amp;nbsp;do&amp;nbsp;this:&amp;nbsp;;&lt;BR /&gt;subgroupSuffix=substr(subgroup,length(subgroup));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, just FYI, you can shorten your code substantially (skipping all the proc means, sorting and extra data steps by doing something like this immediately below your input data step (though use CROSS JOIN with caution):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table incidence_plot as
select a.*, scan(a.subgroup,-1,'-') as subgroupSuffix, b.groupavg, c.overallavg
from
	incidence A
	inner join
	(select group, mean(cumulativeincidence) as groupavg from incidence group by group) B
	on a.group=b.group
	cross join
	(select mean(cumulativeincidence) as overallavg from incidence) C
order by group, subgroup;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It seems like you are just trying to show, within each group (A-D), the group average.&amp;nbsp; I don't see an easy way to do what you're trying to do except to create a separate subgroup within each group for which the value is the group average.&amp;nbsp; &amp;nbsp;This will simply create an additional bar for each group - however, it won't match the Excel version visually.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2025 13:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962586#M25378</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-03-25T13:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Graph Recreation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962632#M25379</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data incidence;
infile datalines truncover;
    input Group $ Subgroup $ CumulativeIncidence ref high low;
	Subgroup=compress(Subgroup,,'ka');
    datalines;
A 1-34A 0.54
A 1-34B 0.42
A 1-34C 0.46
A 1-34D 0.42
A 1-34E 0.37
B 3-34B 0.39
B 3-34C 0.35
B 3-34D 0.43
B 3-34E 0.48
C 3-39A 0.45
C 3-39B 0.44
C 3-39C 0.50
C 3-39D 0.41
C 3-39E 0.35
D 4-39A 0.20
D 4-39B 0.28
D 4-39C 0.29
D 4-39D 0.24
A . . . 0.5 0.5
B . . . 0.4 0.4
C . . . 0.45 0.45
D . . . 0.3 0.3
. . . 0.35 .
;
run;
proc sgplot data=incidence ;
vbarparm category=Group response=CumulativeIncidence/group=Subgroup groupdisplay=cluster 
   datalabel  name='bar';
refline ref/axis=y lineattrs=(pattern=dash color=black) legendlabel='Bridge Average' name='ref';
highlow x=Group high=high low=low/type=bar ;
keylegend 'bar'/location=outside position=s exclude=(' ');
legenditem name='highlow' type=LINE / label='Battery Average' lineattrs=(color=black) ;
keylegend 'highlow' 'ref'/location=inside position=ne across=1 ;
xaxis label='IET Average';
yaxis grid;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1742959689329.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105635iE7D70AC939275644/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1742959689329.png" alt="Ksharp_0-1742959689329.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 03:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962632#M25379</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-26T03:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Graph Recreation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962635#M25380</link>
      <description>&lt;P&gt;If you want get rid of ERROR info, you should use VBARPARM instead of VBAR.&lt;BR /&gt;Check my code to see how to use VBARPARM statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another alternative way is&amp;nbsp; using VBARBASIC to replace VBAR:&lt;/P&gt;
&lt;PRE&gt; vbar Group / response=CumulativeIncidence .......
---&amp;gt;
 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;vbarbasic&lt;/STRONG&gt; &lt;/FONT&gt;Group / response=CumulativeIncidence ........&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Mar 2025 08:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962635#M25380</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-26T08:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Graph Recreation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962650#M25381</link>
      <description>&lt;P&gt;Thank you very much for your assistance! This is exactly what I needed.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 09:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962650#M25381</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2025-03-26T09:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Graph Recreation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962653#M25382</link>
      <description>had no idea you could reference a character variable as the X value in a HIGHLOW statement!</description>
      <pubDate>Wed, 26 Mar 2025 10:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Graph-Recreation/m-p/962653#M25382</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-03-26T10:44:36Z</dc:date>
    </item>
  </channel>
</rss>

