/**********************************************************************/


   /* modify the horizontal axis                                */                                                                                                  
axis1 order=(0 to 650 by 50) label=('Days')                                                                                          
      minor=(number=1) origin=(19,);                                                                                                 
                                                                                                                                     
   /* modify the vertical axis                                  */                                                                                                    
axis2 order=('Opossum' 'Mouse' 'Chipmunk' 'Rabbit'                                                                                   
             'Kangaroo' 'Dog' 'Wolf' 'Guinea Pig'                                                                                    
             'Lion' 'Goat' 'Deer' 'Black Bear'                                                                                       
             'Chimpanzee' 'Gorilla' 'Buffalo' 'Cow'                                                                                  
             'Horse' 'Sea Lion' 'Zebra' 'Camel'                                                                                      
             'Giraffe' 'Rhinoceros' 'Elephant')                                                                                      
      label=none offset=(2,2) major=none;                                                                                            
                                                                                                                                     
   /* define plot symbol                                        */                                                                                                          
symbol value=dot height=2;                                                                                                           
                                                                                                                                     
   /* produce the plot                                          */                                                                                                            
proc gplot data=gest;                                                                                                                
   plot type*days / autovref lvref=2 frame                                                                                           
                    haxis=axis1 vaxis=axis2;                                                                                         
run;                             


/**********************************************************************/


   /* define symbol characteristics                             */                                                                                               
symbol1 interpol=join font=marker value=C height=2.5;                                                                        
                                                                                                                                     
   /* produce the plot                                          */                                                                                                            
proc gplot data=energy;                                                                                                              
   plot consumed*year / frame haxis=axis1 vaxis=axis2;                                                                               
run;       


/**********************************************************************/


proc gchart data=energy;                                                                                                             
   vbar year / discrete sumvar=consumed sum                                                                                  
               maxis=axis1 raxis=axis2                                                                                               
               frame coutline=black width=5;                                                                                         
run;  
           

/**********************************************************************/


   /* modify the vertical axis                                  */                                                                                                    
axis2 label=('Quadrillion' justify=right 'Btu')                                                                                      
      major=(height=1.5) minor=(number=1 height=1)                                                                                   
      order=(35 to 85 by 10);   


/**********************************************************************/


data engychng;                                                                                                                       
   keep year change;                                                                                                                 
   set energy;                                                                                                                       
      /* assign to PREV the value of CONSUMED                   */                                                                                     
      /* for the previous year                                  */                                                                                     
   prev=lag(consumed);                                                                                                               
      /* initialize PREV with value for 1955                    */                                                                                      
   if _n_=1 then prev=38.82;                                                                                                         
      /* calculate the difference between periods               */                                                                                 
   change=consumed-prev;                                                                                                             
run;      


/**********************************************************************/


   /* define symbol characteristics                             */                                                                                               
symbol1 interpol=needle font=swiss value=- height=3                                                                                  
        width=2;                                                                                                                     
                                                                                                                                     
   /* modify the horizontal axis                                */                                                                                                  
axis1 order=(1960 to 1990 by 5) minor=none                                                                                           
      label=none offset=(3,3);                                                                                                       
                                                                                                                                     
   /* modify the vertical axis                                  */                                                                                                    
axis2 order=(-5 to 15 by 5) label=none                                                                                               
      value=(t=1 'Decrease  -5'                                                                                                      
             t=2 'No Change  0'                                                                                                      
             t=5 'Increase  15')                                                                                                     
      minor=(number=1 height=1) offset=(0,);                                                                                         
                                                                                                                                     
                                                                                                                                     
   /* produce plot                                              */                                                                                                                
proc gplot data=engychng;                                                                                                            
   plot change*year / haxis=axis1 vaxis=axis2 vref=0                                                                                 
                      frame;                                                                                                         
run;               


/**********************************************************************/


   /* define symbols for the line plots                         */                                                                                           
symbol1 interpol=join font=marker value=C height=2.5;                                                                                
symbol2 interpol=join value=dot height=3;                                                                                            
                                                                                                                                     
   /* suppress symbols for the PLOT2 plot                       */                                                                                         
symbol3 interpol=none value=none;                                                                                                    
                                                                                                                                     
   /* modify the legend                                         */                                                                                                           
legend1 label=none value=('Consumed' 'Produced');                                                                                    
                                                                                                                                     
   /* produce overlay plot with right vertical axis             */                                                                               
proc gplot data=energy;                                                                                                              
   plot consumed*year=1 produced*year=2                                                                                              
        / shcode overlay legend=legend1                                                                                              
          haxis=axis1 vaxis=axis2 frame;                                                                                             
   plot2 consumed*year=3 / haxis=axis1 vaxis=axis3;                                                                                  
run;                  


/**********************************************************************/


proc transpose data=energy out=energy2(rename=(col1=btu))                                                                            
               name=prodcon;                                                                                                         
   var produced consumed;                                                                                                            
   by year;                                                                                                                          
run;          


/**********************************************************************/


   /* define bar patterns                                       */                                                                                                         
pattern1 value=solid color=black;                                                                                                    
pattern2 value=solid color=grayaa;                                                                                                   
                                                                                                                                     
   /* modify the midpoint axis                                  */                                                                                                    
axis1 minor=none label=none value=none;                                                                                              
                                                                                                                                     
   /* modify the response axis                                  */                                                                                                    
axis2 label=(angle=90 'Quadrillion Btu')                                                                                             
      major=(height=1.5) minor=(number=1 height=1);                                                                                  
                                                                                                                                     
   /* modify the group axis                                     */                                                                                                       
axis3 label=none;                                                                                                                    
                                                                                                                                     
   /* modify legend                                             */                                                                                                               
legend1 label=none shape=bar(3,3)                                                                                                    
        value=('Energy Consumed' 'Energy Produced');                                                                                 
                                                                                                                                     
   /* produce vertical bar chart                                */                                                                                                  
proc gchart data=energy2;                                                                                                            
   prodcon / sumvar=btu group=year subgroup=prodcon                                                                                  
                  maxis=axis1 raxis=axis2 gaxis=axis3                                                                                
                  legend=legend1 coutline=black                                                                                      
                  frame space=0;                                                                                                     
run;                                    


/**********************************************************************/


   /* calculate the difference                                  */                                                                                                    
data engydif;                                                                                                                        
   drop consumed produced;                                                                                                           
   set energy;                                                                                                                       
   diff=consumed-produced;                                                                                                           
run;  


/**********************************************************************/


   /* produce the chart                                         */                                                                                                           
proc gchart data=engydif;                                                                                                            
   vbar year / discrete sumvar=diff sum                                                                                              
               maxis=axis1 raxis=axis2                                                                                               
               frame width=6 coutline=black;                                                                                         
run;   


/**********************************************************************/


   /* create a format for SOURCE                                */                                                                                                  
proc format library=library;                                                                                                         
   value $engyfmt 'coal'='Coal'                                                                                                      
                  'gas'='Natural Gas'                                                                                                
                  'geotherm'='Geothermal'                                                                                            
                  'hydro'='Hydroelectric'                                                                                            
                  'nuclear'='Nuclear'                                                                                                
                  'petro'='Oil';                                                                                                     
run;                                                                                                                                 
                                                                                                                                     
   /* position the legend to the right of the chart             */                                                                               
legend label=('Source' position=(top center)) across=1                                                                               
       position=(right middle) shape=bar(3,3);                                                                                       
                                                                                                                                     
   /* produce the chart                                         */                                                                                                           
proc gchart data=engyprod;                                                                                                           
   format source $engyfmt.;                                                                                                          
   vbar year / discrete sumvar=produced subgroup=source                                                              
               maxis=axis1 raxis=axis2 legend=legend1                                                                                
               width=6 frame coutline=black;                                                                                         
run;                                           


/**********************************************************************/


   /* modify the midpoint axis                                  */                                                                                                    
axis1 minor=none label=none                                                                                                          
      order=('Oil' 'Natural Gas' 'Coal'                                                                                              
             'Hydroelectric' 'Nuclear' 'Geothermal')                                                                                 
      value=(height=2);                                                                                                              
                                                                                                                                     
   /* modify the response axis                                  */                                                                                                    
axis2 label=('Quadrillion Btu')                                                                                                      
      order=(0 to 25 by 5) minor=none;                                                                                               
                                                                                                                                     
   /* modify the group axis                                     */                                                                                                       
axis3 label=none;                                                                                                                    
                                                                                                                                     
   /* produce the chart                                         */                                                                                                           
proc gchart data=engyprod;                                                                                                           
   format source $engyfmt.;                                                                                                          
   hbar source / sumvar=produced group=year nostats                                                                  
                 maxis=axis1 raxis=axis2 gaxis=axis3                                                                                 
                 frame coutline=black;                                                                                               
run;             


/**********************************************************************/


   /* modify the midpoint axis                                  */                                                                                                    
axis1 label=none length=80                                                                                                           
      value=(tick=2 'Geo-' justify=center 'thermal'                                                                                  
             tick=3 'Hydro-' justify=center 'electric'                                                                               
             tick=4 'Natural' justify=center 'Gas');                                                                                 
                                                                                                                                     
   /* modify the response axis                                  */                                                                                                    
axis2 label=(angle=90 'Quadrillion Btu')                                                                                             
      order=(0 to 25 by 5)                                                                                                           
      minor=(number=1);                                                                                                              
                                                                                                                                     
   /* produce the chart                                         */                                                                                                           
proc gchart data=engyprod(where=(year=1990));                                                                                
   format source $engyfmt.;                                                                                                          
   vbar source / sumvar=produced sum descending                                                                                      
                 maxis=axis1 raxis=axis2 width=8                                                                                     
                 frame coutline=black;                                                                                               
run;                          


/**********************************************************************/


proc gchart data=engyprod(where=(source='petro' or                                                                           
                                 source='coal'));                                                                            
   format source $engyfmt.;                                                                                                          
   vbar year / discrete sumvar=produced group=source                                                                                 
               maxis=axis1 raxis=axis2 gaxis=axis3                                                                                   
               width=4 space=1 gspace=3                                                                                              
               ref=20 clipref frame coutline=black;                                                                                  
run;     


/**********************************************************************/


   /* convert values of PRODUCED to integers greater than 1     */                                                                                      
data temp;                                                                                                                           
   set engyprod(where=(year=1990));                                                                                                  
   produced=produced*100;                                                                                                            
run;                                                                                                                                 
                                                                                                                                     
   /* produce chart                                             */                                                                                                               
proc gchart data=temp;                                                                                                               
   format source $engyfmt.;                                                                                                          
   pie source / freq=produced type=percent jstyle                                                                                    
                other=5 otherlabel='Hydro & Geotherm'                                                                                
                noheading coutline=black;                                                                                            
run;           


/**********************************************************************/


proc gplot data=engyprod;                                                                                                            
   format source $engyfmt.;                                                                                                          
   plot produced*year=source / haxis=axis1 vaxis=axis2                                                                               
                               frame legend=legend1;                                                                                 
run;   


/**********************************************************************/


   /* modify the vertical axis                                  */                                                                                                    
axis2 logbase=10                                                                                                             
      label=(angle=90 'Quadrillion Btu (Logbase 10)')                                                                                
      major=(height=1.5) minor=(number=1 height=1);   


/**********************************************************************/


   /* specify symbol characteristics                            */                                                                                              
symbol1 value=circle height=2.5;                                                                                                     
                                                                                                                                     
   /* produce the plot                                          */                                                                                                            
proc gplot data=gpa;                                                                                                                 
   plot satv*satm /frame haxis=axis1 vaxis=axis1;                                                                                    
run;   


/**********************************************************************/


   /* modify response axis                                      */                                                                                                        
axis2  minor=(n=1) label=none;                                                                                                       
                                                                                                                                     
   /* modify midpoint axis                                      */                                                                                                        
axis1 offset=(4,4) label=none major=none length=70;                                                                                  
                                                                                                                                     
   /* produce the chart                                         */                                                                                                           
proc gchart data=gpa;                                                                                                                
   vbar satv satm / type=freq freq frame raxis=axis2                                                                                 
                    maxis=axis1 width=4 coutline=black;                                                                              
run;       


/**********************************************************************/


   /* define symbol characteristics                             */                                                                                               
symbol1 value=circle height=2.5 interpol=rlclm;                                                                                      
                                                                                                                                     
   /* produce the plot                                          */                                                                                                            
proc gplot data=gpa;                                                                                                                 
   plot gpa*satm / frame haxis=axis1 vaxis=axis1;                                                                                    
run;   


/**********************************************************************/


   /* convert STCODE to full state name                         */                                                                                           
data names;                                                                                                                          
   set engymap;                                                                                                                      
   name=stnamel(stcode);                                                                                                             
run;                                                                                                                                 
                                                                                                                                     
   /* produce the ranked bar chart                              */                                                                                                
proc gchart data=names;                                                                                                              
   hbar name / nostats sumvar=btu descending width=.5                                                                                
               autoref frame clipref coutline=black                                                                                  
               maxis=axis1 raxis=axis2;                                                                                              
run;             


/**********************************************************************/


   /* define patterns for the map areas                         */                                                                                           
pattern1 value=msolid color=grayee;                                                                                                  
pattern2 value=msolid color=graybb;                                                                                                  
pattern3 value=msolid color=gray88;                                                                                                  
pattern4 value=msolid color=gray44;                                                                                                  
                                                                                                                                     
   /* describe midpoint ranges                                  */                                                                                                    
legend1 value=('0-300' '301-600' '601-900' 'Over 900')                                                                               
        shape=bar(3,3) label=('Millions of Btu');                                                                                    
                                                                                                                                     
   /* produce an outline map                                    */                                                                                                      
proc gmap data=engymap map=maps.us;                                                                                                  
   id state;                                                                                                                         
   choro btu / midpoints=(150,450,750,1050)                                                                                       
               legend=legend1 coutline=black;                                                                                        
run;        


/**********************************************************************/