ASIS=ON does not maintain leading or trailing blanks in the output generated by the ExcelXP tagset


The ExcelXP tagset creates XML files and does not, by default, have the ability to preserve leading blanks. An attempt to use the style attribute ASIS=ON does not preserve leading blanks.
To circumvent the problem, use an update to the ExcelXP tagset, and maintain leading blanks with the non-breaking space character  . This is demonstrated in the Full Code section.

An alternative is to use the MSOffice2K tagset, which does preserve leading blanks. Sample code is also shown in the Full Code section.


Full Code

The following code illustrates two workarounds. The first creates a new tagset based on the ExcelXP tagset. It then updates the VALUE_PUT event, and uses the   non-breaking space character to maintain the leading blanks in the XML file created with this tagset.
The second workaround illustrates the use of the MSOffice2K tagset. The ORIGIN values ASIA and USA are indented slightly using the PRETEXT= style setting. These leading blanks are maintained with the ASIS=ON style attribute setting. In order to prevent tall cell heights, the HEADTEXT= option is necessary in the ODS TAGSETS statement.

/* Workaround using the ExcelXP tagset */
proc template;
   define tagset tagsets.excelxp_mod;
      parent=tagsets.excelxp;

 /**************************************************************************/
 /* Add the PRETEXT and the POSTEXT= style variable to the VALUE_PUT event */
 /**************************************************************************/

         define event value_put;

            open row;

            do /if ^$value_put;

               do /if cmp( event_name, "header");

                  trigger value_type;
                  set $tmp_val strip(value);
                  set $type "String" /if ^$tmp_val;
                  unset $tmp_val;
               done;

               putq "<Data ";

               do /if $value;
                  putq "ss:Type=" $type;

               else;
                  putq "ss:Type=""String""";
               done;

               put ">";
               set $value_put "true";
               unset $type;
            done;
            put pretext;
            put $value;
            put posttext;
            unset $value;
      end;
   end;
run;

ods tagsets.excelxp_mod file="excelxp.xls";
                                                                                                                                  
proc report data=sashelp.cars nowd;                                                                                                    
   col origin cylinders mpg_highway mpg_city;                                                                                           
   define origin      / group;                                                                                                         
   define cylinders   / group;                                                                                                         
   define mpg_highway / mean format=4.;                                                                                                
   define mpg_city    / mean format=4.;                                                                                                
                                                                                                                                        
   compute origin;                                                                                                                       
      if origin ne "Europe" then do;                                                                                                      
         call define(_col_,"style","style={pretext='&nbsp;&nbsp;&nbsp;&nbsp;'}");                                                      
      end;                                                                                                                                
   endcomp;                                                                                                                                                                                                                                                                     
run;   
 
ods _all_ close;   


/* Workaround using the MSOffice2K tagset */                                                                                                                                                 
ods tagsets.msoffice2k file='msoffice2k.xls' headtext="<style> pre {margin:0}</style>" ;                                               
 
proc report data=sashelp.cars nowd;                                                                                                    
   col origin cylinders mpg_highway mpg_city;                                                                                           
   define origin        / group;                                                                                                         
   define cylinders     / group;                                                                                                         
   define mpg_highway   / mean format=4.;                                                                                                
   define mpg_city      / mean format=4.;                                                                                                
                                                                                                                                        
   compute origin;                                                                                                                       
      if origin ne "Europe" then do;                                                                                                      
         call define(_col_,"style","style={pretext='   ' asis=on}");                                                      
      end;                                                                                                                                
   endcomp;                                                                                                                              
run;                                                                                                                                        
                                                                                                                                   
ods _all_ close;       


Output

Click here to view the output