Hi,
How to change the order of vertical bars as requested by the question below?
B. How would you rewrite the cont format to arrange the bars in alphabetical order? You could accomplish this by using a chart statement.
Thank you in advance.
data demog; input id contry $ 5-17 pop 19-22 pcturb 24-25 energy 27-29 cult 31-32 pasture 34-35 forest 37-38; cards; 101 China 1062 32 19 11 30 14 107 Japan 122 76 111 13 2 68 113 Philippines 62 40 9 38 4 40 102 India 800 25 7 51 4 21 112 Vietnam 62 19 4 20 1 40 109 Bangladesh 107 . . . . . 105 Indonesia 175 . . . . . 110 Paskistan 105 28 6 25 6 4 304 United States 243 74 280 20 26 28 311 Mexico 82 70 50 13 38 23 406 Brazil 141 71 19 9 19 66 508 Nigeria 109 28 7 34 23 16 603 USSR 284 65 176 10 17 42 614 West Germany 61 85 163 30 19 29 615 Italy 57 72 90 41 16 21 ; proc print; run; proc format; value cont 100-199='Asia' 200-299='Australasia' 300-399='N. America' 400-499='S. America' 500-599='Africa' 600-699='Europe'; run; data demog1; FORMAT id cont.; set demog; rename id=cont; TITLE '5a. Recode country number as continent name'; proc print; run; proc chart data=demog1; vbar energy/group=cont subgroup=contry discrete SUMVAR=energy type=mean; title '5a. Chart with format'; run;
I haven't seen anyone actually proc CHART since about 1987 as the Text Based graphic procedures have gone way out of style.
If I recall correctly the horizontal axis uses the mid point of a numerical value then applies the format as the value.
So if the goal is to get things in order you need to create a new character variable that will sort itself by default.
data work.demog1; FORMAT id cont.; set work.demog; rename id=cont; conttext = put(id,cont.); run; TITLE '5a. Recode country number as continent name'; proc chart data=work.demog1; vbar energy/group=conttext subgroup=contry discrete SUMVAR=energy type=mean; title '5a. Chart with format'; run; title;
Alphabetical order of which variable?
I haven't seen anyone actually proc CHART since about 1987 as the Text Based graphic procedures have gone way out of style.
If I recall correctly the horizontal axis uses the mid point of a numerical value then applies the format as the value.
So if the goal is to get things in order you need to create a new character variable that will sort itself by default.
data work.demog1; FORMAT id cont.; set work.demog; rename id=cont; conttext = put(id,cont.); run; TITLE '5a. Recode country number as continent name'; proc chart data=work.demog1; vbar energy/group=conttext subgroup=contry discrete SUMVAR=energy type=mean; title '5a. Chart with format'; run; title;
@Amy0223 wrote:
Amazing! Thank you so much!! I don't know why we had to use proc CHART but it works!
Is this for a class? It may be that the teacher just hasn't bothered to update examples or is going to add in the "prettier" graphs later.
Text based graphics, while not very pretty are portable across operating systems. if you can generate a text file then you get the output. That was not the case in the older SAS/Graph procedures such as GChart and GPlot that had device based output. So a teacher may keep older things floating around to avoid having to get into device drivers and such.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: