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


data sales;                
   input date date7. sales;
   cards;                  
01jan91 200                
01feb91 300                
01mar91 250                
01apr91 300                
01may91 400                
01jun91 325                
run;


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


data sales;                        
   input month $ sales;            
   date=input('01'||month,date7.); 
   cards;                          
jan91 200                          
feb91 300                          


         
jun91 325
run;     
 

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


proc gplot data=sales;
   plot sales*date;   
run;
 

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


proc gplot data=sales;
   plot sales*date;   
   format date date7.;
run;
 

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


proc gplot;                                       
   plot sales*date                                
        / haxis='01jan91'd to '01jun91'd by month;
   format date date7.;                            
run; 


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


axis1 order='01jan91'd to '01feb91'd by 2;


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


axis1 order='2:00:00't to '2:05:00't by 30;


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


proc gplot data=carpool;                            
   plot riders*date                                 
        / haxis='01sep92'd to '11sep92'd by weekday;
   format date date5.;                              
run;                                                


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


proc gplot data=saledata;                             
   plot sales*date                                    
        / haxis='01jan92'd to '01apr92'd by semimonth;
   format date date5.;                                
run;                                                  


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


proc gplot data=saledata;                                   
   plot sales*date/haxis='01jan91'd to '01jan92'd by month2;
   format date monyy5.;                                     
run;


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


proc format;                         
   value myfmt '20dec92'd='Chanukah' 
               '25dec92'd='Christmas'
               '01jan93'd='New Year' 
   '19dec92'd, '02jan93'd=(|date5.|) 
                    other=(|day2.|); 
                                     
axis1 value=(a=80 r=0) minor=none    
      label=('U.S. Holiday Season')  
      order='19dec92'd to '02jan93'd;
                                     
proc gplot;                          
   plot value*date / haxis=axis1;    
   format date myfmt.;               
run;                                 
quit;                                


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


proc gplot;                                           
   plot CPU*time / haxis='18:00't to '23:00't by hour,
      '0:00't to '17:00't by hour;                    
   format time time5.;
run;


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


data one;                                             
   input startime time5. count;                       
   if startime gt '12:00't then date='30sep92'd;      
      else date='01oct92'd;                           
   datetime=dhms(date,hour(startime),minute(startime),
            second(startime));                        
   cards;                                             
16:00 12.3                                            
17:00 5.7                                             
18:00 8.6                                             
19:00 9.0
20:00 15.7                                            
21:00 10.5                                            
22:00 8.1                                             
23:00 1.5                                             
0:00  11.3                                            
1:00  6.6                                             
2:00  3.5                                             
3:00  7.6                                             
4:00  2.4                                             
5:00  13.8                                            
6:00  14.0                                            
7:00  4.9                                             
8:00  5.0                                             
run;                                                  
                                                      
proc gplot data=one;                                  
   plot count*datetime                                
        / haxis='30sep92:16:00'dt to '01oct92:08:00'dt
                by hour2;                             
   format datetime tod5.;                             
run;                                                                                                                                                                                                                                                            


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


data sales;                 
   input month date7. sales;
   cards;                   
01sep91 400                 
01oct91 420                 
01nov91 450                 
01dec91 475                 
01jan92 300                 
01feb92 400                 
01mar92 350                 
01apr92 400                 
01may92 200                 
01jun92 225                 
01jul92 300                 
01aug92 450                 
01sep92 400                 
01oct92 320                 
01nov92 450                                                                                                                                                                                                         
01dec92 475                                                 
01jan93 300                                                 
01feb93 400                                                 
run;                                                        
                                                            
   /* determine most recent month in data                 */
proc means data=sales max noprint;                          
   var month;                                               
   output out=months max=max;                               
run;                                                        
                                                            
   /* calculate beginning month and store                 */
   /* beginning and ending month as macro variables       */
data _null_;                                                
   set months;                                              
   min=intnx('month',max,-11);                              
   call symput                                              
        ('monthmin',left(put(min,date7.)));                 
   call symput                                              
        ('monthmax',left(put(max,date7.)));                 
run;                                                        
                                                            
   /* generate plot, using macro variables in axis        */
   /* specification                                       */
proc gplot data=sales;                                      
   plot sales*month                                         
        / haxis="&monthmin"d to "&monthmax"d by month;      
   format month  monname3.;                                 
   symbol1 i=join;                                          
   title h=5 pct 'Plot of last 12 months';
run;


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


axis1 order='01jan91'd to '01mar92'd by month
      value=(t=1 'J' j=c '1991'   
             t=13 'J' j=c '1992');
                                  
proc gplot data=sales;            
   plot sales*date / haxis=axis1; 
   format date monname1.;         
run;


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


data sales;                
   input date date7. sales;
   cards;                  
01jan91 200                
01feb91 300                
01mar91 250                
01apr91 300
01may91 400                                                 
01jun91 325                                                 
01jul91 400                                                 
01aug91 350                                                 
01sep91 400                                                 
01oct91 420                                                 
01nov91 450                                                 
01dec91 475                                                 
01jan92 200                                                 
01feb92 300                                                 
01mar92 250                                                 
run;                                                        
                                                            
   /* determine beginning and ending dates                */
proc means data=sales min max noprint;                      
   var date;                                                
   output out=times min=datemin max=datemax;                
run;                                                        
                                                            
data _null_;                                                
   set times;                                               
                                                            
      /* Jan 1 of first year in data                      */
   min=(intnx('year',datemin,0));                           
                                                            
      /* Jan 1 of last year in data                       */
   max=(intnx('year',datemax,1));                           
                                                            
      /* total number of ticks                            */
   nticks=intck('month',min,max+1);
                                                            
      /* store number of ticks as macro var               */
   call symput('nticks',nticks);                            
                                                            
      /* &mindate is Jan 1 of first year                  */
   call symput                                              
      ('mindate',left(put(min,date7.)));                    
                                                            
      /* &maxdate is Jan 1 of last year                   */
   call symput                                              
      ('maxdate',left(put(max,date7.)));                    
                                                            
   do i=1 to nticks by 12;                                  
      call symput('year'||left(i),                          
                   left(put(intnx('month',min,i-1),         
                   year4.)));                               
   end;                                                     
run;                                                        
                                                            
   /* define the macro                                    */
%macro haxis;                                               
   axis1 order="&mindate"d to "&maxdate"d by month          
         value=(                                            
    %do i=1 %to &nticks %by 12;                             
         T=&i "J" J=C "&&year&i"                            
    %end;                                                   
   );                                                       
%mend;                                                      
                                                            
   /* invoke the macro           
%haxis;                          
                                 
proc gplot data=sales;           
   plot sales*date / haxis=axis1;
   format date monname1.;        
run;                             
quit;                            


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