BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Amy0223
Quartz | Level 8

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

9 REPLIES 9
Reeza
Super User
You should use SGPLOT instead. Then you can specify order=data to get the order you want.

In general, SG graphics are easier to control and have better quality graphs as well. GCHART/CHART are very old procedures and you shouldn't be developing new graphs with those IMO.
Amy0223
Quartz | Level 8
Thank you for the information. I learned something new! The question given by my instructor required us to use a chart statement so I did it this way. Do you know how to change the order given the data provided? I greatly appreciate your response!
Reeza
Super User
No instructor should be teaching a CHART statement these days.

Sorry, no I don't know the CHART procedure, I know the SG procedures.
Amy0223
Quartz | Level 8
Ok, thank you for taking time!
ballardw
Super User

Alphabetical order of which variable?

 

 

Amy0223
Quartz | Level 8
I think it means cont variable. Thanks!
ballardw
Super User

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
Quartz | Level 8
Amazing! Thank you so much!! I don't know why we had to use proc CHART but it works!
ballardw
Super User

@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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1117 views
  • 5 likes
  • 3 in conversation