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


options ps=60 nodate nonumber;                             
                                                           
data track;                                                
   length type $ 12;                                       
   input date date7. type $ morning midday evening bedtime;
   format date date7.;                                     
   cards;                                                  
01JAN92 Insulin 2 6 8 9                                    
01JAN92 Sugar 119 134 126 115                              
02JAN92 Insulin 2 6 8 9                                    
02JAN92 Sugar 306 179 267 189                              
03JAN92 Insulin 2 6 8 9                                    
03JAN92 Sugar 229 150 139 140                              
04JAN92 Insulin 2 5 8 9                                    
04JAN92 Sugar 121 156 200 162                              
05JAN92 Insulin 2 7 8 8        
05JAN92 Sugar 113 205 346 189  
06JAN92 Insulin 2 6 8 8        
06JAN92 Sugar 78 105 119 122   
07JAN92 Insulin 2 6 8 8        
07JAN92 Sugar 134 162 128 400  
;                              
                               
proc print data=track;         
   title 'The TRACK Data Set'; 
run;


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


proc transpose data=track out=simpletr;
run;                                   
                                       
proc print data=simpletr;              
   title 'The SIMPLETR Data Set';      
run;


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


proc transpose data=track out=blsugar name=time let;
   id date;                                         
run;                                                
                                                    
proc print data=blsugar;                            
   title 'The BLSUGAR Data Set';                    
run;


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


proc format;                                             
   picture starfmt 300-high='000999' (fill='*');         
run;                                                     
                                                         
proc transpose data=track out=blsugar name=time let;     
   attrib _: format=starfmt.;                            
   id date;                                              
run;                                                     
                                                         
proc print data=blsugar;                                 
   title 'The BLSUGAR Data Set with High Values Flagged';
run; 


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


proc means data=blsugar maxdec=2 mean std;        
   title 'Daily Statistics for Blood Sugar Level';
run;


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


proc transpose data=track out=bydate;
   by date;                          
run;                                 

proc print data=bydate;              
   title 'The BYDATE Data Set';      
run; 


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


proc transpose data=track out=bydate name=time;
   by date;                                    
   id type;                                    
run;                                           
                                               
proc print data=bydate;                        
   title 'The BYDATE Data Set';                
run;                                                                                                                                                                                                                                                            


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


options formdlim=' ';                       
                                            
proc means data=bydate mean maxdec=2;       
   class time;                              
   var sugar insulin;                       
   title 'Mean for Blood Sugar and Insulin';
   title2 'for Each Time of Day';           
run;                                        
                                            
proc means data=bydate mean maxdec=2;       
   var sugar insulin;                                                                                                                                                                                                                                           
   title 'Overall Mean for the Week';
run;                                 


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


proc gchart data=bydate;                          
   block time / sumvar=sugar type=mean;           
   title 'Mean Sugar Levels for Each Time of Day';
run;                                              
quit;                                                                                                                                                                                                                                                           
 

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


proc gchart data=bydate;                                  
   block time / sumvar=sugar type=mean midpoints='MORNING'
                'MIDDAY' 'EVENING' 'BEDTIME';             
   attrib time label='Time of Day' sugar format=6.2;      
run;                                                                                                                                                                                                                                                            
 

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


data transp;                                                
   input date date7. type1 $ morning midday evening bedtime 
         / @9 type2 $ mornsug noonsug evesug bedsug;        
   array x{4} morning midday evening bedtime;               
   array y{4} mornsug noonsug evesug bedsug;                
   length _name_ $ 8;                                       
   do i=1 to 4;                                             
      call vname(x{i},_name_);                              
      col1=x{i};                                            
      col2=y{i};                                            
      output;                                               
   end;                                                     
   attrib date format=date7.;                               
   keep date _name_ col1 col2;                              
   cards;                                                   
01JAN92 Insulin 2 6 8 9                                     
01JAN92 Sugar 119 134 126 115                               
02JAN92 Insulin 2 6 8 9                                     
02JAN92 Sugar 306 179 267 189                               
03JAN92 Insulin 2 6 8 9                                     
03JAN92 Sugar 229 150 139 140                                                                                                                                                                                                                                   
04JAN92 Insulin 2 5 8 9         
04JAN92 Sugar 121 156 200 162   
05JAN92 Insulin 2 7 8 8         
05JAN92 Sugar 113 205 346 189   
06JAN92 Insulin 2 6 8 8         
06JAN92 Sugar 78 105 119 122    
07JAN92 Insulin 2 6 8 8         
07JAN92 Sugar 134 162 128 400   
;                               
                                
proc print data=transp;         
   title 'The TRANSP Data Set'; 
run;                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                               

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