<?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 Am I using the right using proc sort or by function? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Am-I-using-the-right-using-proc-sort-or-by-function/m-p/72922#M21154</link>
    <description>Hi Guys,&lt;BR /&gt;
&lt;BR /&gt;
I am a newly minted stat masters student and am using SAS for the first time in my life. I do need some help with some SAS coding to get what my professor wants.&lt;BR /&gt;
&lt;BR /&gt;
I will post the code here:&lt;BR /&gt;
&lt;BR /&gt;
data Police;&lt;BR /&gt;
input County $ 1-10 Officers Assaults;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Atlantic 961 143&lt;BR /&gt;
Bergen 2177 213&lt;BR /&gt;
Burlington 786 109&lt;BR /&gt;
Camden 1360 199&lt;BR /&gt;
Cape May 343 36&lt;BR /&gt;
Cumberland 291 52&lt;BR /&gt;
Essex 2833 429&lt;BR /&gt;
Gloucester 583 113&lt;BR /&gt;
Hudson 1940 323&lt;BR /&gt;
Hunterdon 182 8&lt;BR /&gt;
Mercer 929 155&lt;BR /&gt;
Middlesex 1602 158&lt;BR /&gt;
Momouth 1499 177&lt;BR /&gt;
Morris 1080 75&lt;BR /&gt;
Ocean 1064 134&lt;BR /&gt;
Passaic 1126 202&lt;BR /&gt;
Salem 125 19&lt;BR /&gt;
Somerset 603 51&lt;BR /&gt;
Sussex 201 31&lt;BR /&gt;
Union 1438 275&lt;BR /&gt;
Warren 153 12&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc print noobs data=Police;&lt;BR /&gt;
var County Officers Assaults;&lt;BR /&gt;
title Assaults on New Jersey Police Officers;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sgplot data=Police;&lt;BR /&gt;
xaxis label="County";&lt;BR /&gt;
yaxis label="Count";&lt;BR /&gt;
vbar County/ response=Officers&lt;BR /&gt;
barwidth=0.5&lt;BR /&gt;
transparency=0.2;&lt;BR /&gt;
vbar County/ response=Assaults;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I would like for my vbar chart to be sorted in descending order using Officers as the variable. I tried using proc sort under data but it did not work for vbar. Alternatively, I tried sorting using a by statement in proc sgplot and what I got in return were 21 singular charts. I am a little stumped as to what I am doing wrong.&lt;BR /&gt;
&lt;BR /&gt;
Can anyone help? Any help is very much appreciated!&lt;BR /&gt;
&lt;BR /&gt;
Henry</description>
    <pubDate>Thu, 16 Sep 2010 23:13:48 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-09-16T23:13:48Z</dc:date>
    <item>
      <title>Am I using the right using proc sort or by function?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Am-I-using-the-right-using-proc-sort-or-by-function/m-p/72922#M21154</link>
      <description>Hi Guys,&lt;BR /&gt;
&lt;BR /&gt;
I am a newly minted stat masters student and am using SAS for the first time in my life. I do need some help with some SAS coding to get what my professor wants.&lt;BR /&gt;
&lt;BR /&gt;
I will post the code here:&lt;BR /&gt;
&lt;BR /&gt;
data Police;&lt;BR /&gt;
input County $ 1-10 Officers Assaults;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Atlantic 961 143&lt;BR /&gt;
Bergen 2177 213&lt;BR /&gt;
Burlington 786 109&lt;BR /&gt;
Camden 1360 199&lt;BR /&gt;
Cape May 343 36&lt;BR /&gt;
Cumberland 291 52&lt;BR /&gt;
Essex 2833 429&lt;BR /&gt;
Gloucester 583 113&lt;BR /&gt;
Hudson 1940 323&lt;BR /&gt;
Hunterdon 182 8&lt;BR /&gt;
Mercer 929 155&lt;BR /&gt;
Middlesex 1602 158&lt;BR /&gt;
Momouth 1499 177&lt;BR /&gt;
Morris 1080 75&lt;BR /&gt;
Ocean 1064 134&lt;BR /&gt;
Passaic 1126 202&lt;BR /&gt;
Salem 125 19&lt;BR /&gt;
Somerset 603 51&lt;BR /&gt;
Sussex 201 31&lt;BR /&gt;
Union 1438 275&lt;BR /&gt;
Warren 153 12&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc print noobs data=Police;&lt;BR /&gt;
var County Officers Assaults;&lt;BR /&gt;
title Assaults on New Jersey Police Officers;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sgplot data=Police;&lt;BR /&gt;
xaxis label="County";&lt;BR /&gt;
yaxis label="Count";&lt;BR /&gt;
vbar County/ response=Officers&lt;BR /&gt;
barwidth=0.5&lt;BR /&gt;
transparency=0.2;&lt;BR /&gt;
vbar County/ response=Assaults;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I would like for my vbar chart to be sorted in descending order using Officers as the variable. I tried using proc sort under data but it did not work for vbar. Alternatively, I tried sorting using a by statement in proc sgplot and what I got in return were 21 singular charts. I am a little stumped as to what I am doing wrong.&lt;BR /&gt;
&lt;BR /&gt;
Can anyone help? Any help is very much appreciated!&lt;BR /&gt;
&lt;BR /&gt;
Henry</description>
      <pubDate>Thu, 16 Sep 2010 23:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Am-I-using-the-right-using-proc-sort-or-by-function/m-p/72922#M21154</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-16T23:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Am I using the right using proc sort or by function?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Am-I-using-the-right-using-proc-sort-or-by-function/m-p/72923#M21155</link>
      <description>Hi:&lt;BR /&gt;
  You said: "I tried using proc sort under data but it did not work for vbar. Alternatively, I tried sorting using a by statement in proc sgplot and what I got in return were 21 singular charts." Your instinct to do a sort was correct, but your approach -- to use a "BY statement in PROC SGPLOT" or a "PROC SORT under DATA" -- was flawed.&lt;BR /&gt;
 &lt;BR /&gt;
  Using a BY statement in any procedure or DATA step does not actually PERFORM the sort -- it only uses the sorted data -- generally, as you saw, to treat each BY group as a unit to be handled separately -- such as when you got 21 separate charts. I'm not sure what you mean by saying you tried PROC SORT "under" a DATA I suspect you mean that you added a PROC SORT in the code after your DATA step where you created the POLICE dataset -- this was CORRECT, if you had this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sort data=police;&lt;BR /&gt;
  by descending Officers;&lt;BR /&gt;
run; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                              &lt;BR /&gt;
which produces a sorted version of the POLICE dataset with the rows organized in descending order based on the value of the OFFICERS variable.&lt;BR /&gt;
 &lt;BR /&gt;
The next thing would be to look up the XAXIS statement  for PROC SGPLOT -- you can control the order of the XAXIS or YAXIS (from the default) by using options on the XAXIS or YAXIS statement. The option you would be interested in for the XAXIS would be the DISCRETEORDER= option (since the XAXIS is a "discrete" axis with one bar for every value of the character variable COUNTY).&lt;BR /&gt;
 &lt;BR /&gt;
When I do transparent overlays, I like to make the "underneath" bar a little bigger and make the "on top" bar the transparent bar, as shown below.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
  &lt;BR /&gt;
ps -- in the future, you might want to post SGPLOT questions in the ODS GRAPHICS and SAS/GRAPH forum&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sgplot data=Police;&lt;BR /&gt;
xaxis label="County"  discreteorder=data;&lt;BR /&gt;
yaxis label="Count";&lt;BR /&gt;
&lt;BR /&gt;
vbar County/ response=Officers&lt;BR /&gt;
     barwidth=0.75;&lt;BR /&gt;
                    &lt;BR /&gt;
vbar County/ response=Assaults&lt;BR /&gt;
     barwidth=.5 &lt;BR /&gt;
     transparency=0.2;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 17 Sep 2010 17:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Am-I-using-the-right-using-proc-sort-or-by-function/m-p/72923#M21155</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-17T17:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Am I using the right using proc sort or by function?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Am-I-using-the-right-using-proc-sort-or-by-function/m-p/72924#M21156</link>
      <description>Thank you so much Cynthia for your help, will try to fix my situation.</description>
      <pubDate>Sun, 19 Sep 2010 18:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Am-I-using-the-right-using-proc-sort-or-by-function/m-p/72924#M21156</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-19T18:35:23Z</dc:date>
    </item>
  </channel>
</rss>

