<?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: bar chart for multiple variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/bar-chart-for-multiple-variables/m-p/923438#M41418</link>
    <description>&lt;P&gt;Part of the issue here is that SAS expects the data in a particular layout or arrangement in order for its PROCs to work. That layout is called the "long" data set, where each observation is its own row. Values of Source are in a variable called Source and not in the variable name. This is true for almost all data analysis PROCs, not just plotting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first, you must re-arrange your data into the long arrangement. Then plotting is simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data re_arrange;
	set have;
	source='A';
	value=source_a;
	output;
	source="B";
	value=source_b;
	output;
	drop source_a source_b;
run;
proc sgplot data=re_arrange;
    vbar source/response=value stat=mean;
    yaxis label='Percent' min=0 max=1 valuesformat=percent8.0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Apr 2024 16:44:50 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-04-08T16:44:50Z</dc:date>
    <item>
      <title>bar chart for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/bar-chart-for-multiple-variables/m-p/923429#M41415</link>
      <description>&lt;P&gt;I am comparing two sources of information, and I want to create a bar chart to demonstrate these differences.&lt;/P&gt;&lt;P&gt;My data looks like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD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;nbsp;Source_A and it shows the percentage/frequency of the value 1 (50%), and another bar in the same figure for&amp;nbsp;Source_B value 1 percentage/frequency (70%).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 16:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/bar-chart-for-multiple-variables/m-p/923429#M41415</guid>
      <dc:creator>HijB</dc:creator>
      <dc:date>2024-04-08T16:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: bar chart for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/bar-chart-for-multiple-variables/m-p/923438#M41418</link>
      <description>&lt;P&gt;Part of the issue here is that SAS expects the data in a particular layout or arrangement in order for its PROCs to work. That layout is called the "long" data set, where each observation is its own row. Values of Source are in a variable called Source and not in the variable name. This is true for almost all data analysis PROCs, not just plotting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first, you must re-arrange your data into the long arrangement. Then plotting is simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data re_arrange;
	set have;
	source='A';
	value=source_a;
	output;
	source="B";
	value=source_b;
	output;
	drop source_a source_b;
run;
proc sgplot data=re_arrange;
    vbar source/response=value stat=mean;
    yaxis label='Percent' min=0 max=1 valuesformat=percent8.0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 16:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/bar-chart-for-multiple-variables/m-p/923438#M41418</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-08T16:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: bar chart for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/bar-chart-for-multiple-variables/m-p/923506#M41425</link>
      <description>&lt;P&gt;SAS does have Proc Transpose that often is helpful in rearranging data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input ID	 Source_A	Source_B;
datalines;
1	1	1
2	0	0
3	1	1
4	1	1
5	0	1
6	1	0
7	0	1
8	0	1
9	0	0
10	1	1
;

proc transpose data=have out=trans;
  by id;
run;

proc sgplot data=trans;
   vbar _name_ / response=col1 state=mean;
run;&lt;/PRE&gt;
&lt;P&gt;And different types of values may call for slightly different plots:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=trans;
   vbar _name_ / group=col1 ;
   label _name_ ='Source'
         col1='Value'
   ;
run;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=trans;
   vbar _name_ / group=col1 groupdisplay=cluster;
   label _name_ ='Source'
         col1='Value'
   ;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 21:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/bar-chart-for-multiple-variables/m-p/923506#M41425</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-08T21:10:54Z</dc:date>
    </item>
  </channel>
</rss>

