<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PROC REPORT variable names that begin and end with an underscore. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969312#M376828</link>
    <description>&lt;P&gt;The suggestion by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;to modify the variable label is the most effective work around, renaming is as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;works as long as the variable name is LE 30 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I implemented modifying the label using M_EXPAND_VARLIST.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;817        %let label = %m_expand_varlist(data=test,where=(_name_ like '\_%\_' escape '\'),expr=catx('=',nliteral(_name_),quote(cats('_',_name_,'_'))));
818        %put NOTE: &amp;amp;=label;
NOTE: LABEL=_TYPE_="__TYPE__" _FREQ_="__FREQ__"
819        
820        ods excel file='.\test.xlsx';
821        ods listing close;
822        proc report data=test list;
823           columns _all_;
824           define _all_ / display;
825           attrib _all_ label=' ';
826           label &amp;amp;label;
827           run;
NOTE: Multiple concurrent threads will be used to summarize data.
PROC REPORT DATA=WORK.TEST LS=256 PS=60  SPLIT="/" NOCENTER ;
COLUMN  ( Age Sex Name _TYPE_ _FREQ_ );
 
DEFINE  Age / DISPLAY FORMAT= $12. WIDTH=12    SPACING=2   LEFT "Age" ;
DEFINE  Sex / DISPLAY FORMAT= $1. WIDTH=1     SPACING=2   LEFT "Sex" ;
DEFINE  Name / DISPLAY FORMAT= $8. WIDTH=8     SPACING=2   LEFT "Name" ;
DEFINE  _TYPE_ / DISPLAY FORMAT= $3. WIDTH=3     SPACING=2   LEFT "__TYPE__" ;
DEFINE  _FREQ_ / DISPLAY FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "__FREQ__" ;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro
   m_expand_varlist /*Returns an expanded variable list and optionally creates an indexed data set of variable names*/
      (
         data  = _LAST_,            /*[R]Input data*/
         var   = _ALL_,             /*[R]Variable List expanded*/
         copy  = &amp;amp;var,              /*[O]Copy &amp;amp;VARS to the OUT= data set*/
         where = 1,                 /*[R]Where clause to subset OUT=, useful for selecting by a name suffix e.g. where=_name_ like '%_Status'*/
         expr  = nliteral(&amp;amp;name),   /*[R]An expression that can be used to modify the names in the expanded list*/
         keep  = ,                  /*[O]Keep data set option for DATA=*/
         drop  = ,                  /*[O]Drop data set option for DATA=*/
         rename= ,                  /*[O]Rename data set option for DATA=*/
         out   = work._deleteme_,   /*[O]Output data indexed by _NAME_ and _INDEX_*/
         name  = _NAME_,            /*[R]Name of the variable name variable in the output data set*/
         label = _LABEL_,           /*[R]Name of the variable label variable in the output data set*/
         index = _INDEX_,           /*[R]Name of the variable index variable in the output data set*/
         dlm   = ' '                /*[R]List delimiter*/
      );
   %local m i;
   %let i=&amp;amp;sysindex;
   %let m=&amp;amp;sysmacroname._&amp;amp;i;
   %do %while(%symexist(&amp;amp;m));
      %let i = %eval(&amp;amp;i + 1);
      %let m=&amp;amp;sysmacroname._&amp;amp;i;
      %end;
   /*%put NOTE: &amp;amp;=m is a unique symbol name;*/
   %local rc &amp;amp;m code1 code2 code3 code4 code5;
   %let code1 = %str(options notes=0; proc transpose name=&amp;amp;name label=&amp;amp;label data=&amp;amp;data(obs=0 keep=&amp;amp;keep drop=&amp;amp;drop rename=(&amp;amp;rename)) out=&amp;amp;out(where=(&amp;amp;where)); var &amp;amp;var; copy &amp;amp;copy; run;);
   %let code2 = %str(data &amp;amp;out(index=(&amp;amp;index &amp;amp;name)); set &amp;amp;out; &amp;amp;index+1; run;);
   %let code3 = %str(proc sql noprint; select &amp;amp;expr into :&amp;amp;m separated by &amp;amp;dlm from &amp;amp;out; quit;);
   %if %superq(OUT) eq %str(work._deleteme_) %then %let code4=%str(proc delete data=work._deleteme_; run;);
   %let code5 = %str(options notes=1;);
   %let rc=%sysfunc(dosubl(&amp;amp;code1 &amp;amp;code2 &amp;amp;code3 &amp;amp;code4 &amp;amp;code5));
&amp;amp;&amp;amp;&amp;amp;m.
   %mend m_expand_varlist;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 Jun 2025 13:47:02 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2025-06-18T13:47:02Z</dc:date>
    <item>
      <title>PROC REPORT variable names that begin and end with an underscore.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969256#M376803</link>
      <description>&lt;P&gt;Below you will notice that _TYPE_ and _FREQ_ have lost the underscore.&amp;nbsp; I know that PROC REPORT has special processing for header strings that begin and end with dash, underscore and some others I don't remember.&amp;nbsp; Can I get PROC REPORT to NOT do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Update:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Note: The use of expanding characters is supported only in LISTING destinations. Therefore, PROC REPORT simply removes the expanding characters &lt;BR /&gt;when the output is directed to any other destination. Refer to Understanding ODS Destinations in SAS Output Delivery System: &lt;BR /&gt;User’s Guide for more information.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess the answer is NO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 278px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107888i49844C05793695D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class missing chartype descendtypes;;
   class age sex name / mlf;
   ways 1;
   output out=test;
   run;

ods excel file='.\test.xlsx';

proc report data=test;
   columns _all_;
   define _all_ / display;
   format _type_ $char3.;
   run;

ods excel close;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2025 22:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969256#M376803</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-06-17T22:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT variable names that begin and end with an underscore.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969262#M376804</link>
      <description>&lt;P&gt;John King,&lt;/P&gt;
&lt;P&gt;Yeah. In old destionation LISTING, sas would print _FREQ_ as&amp;nbsp;&amp;nbsp;__________FREQ___________ .&lt;/P&gt;
&lt;P&gt;But I don't understand since yours is not LISTING , why sas would keep this weird behavior.&lt;/P&gt;
&lt;P&gt;Anyway, a workaround way is renaming it ,but that is really clumsy . You like it ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class missing chartype descendtypes;;
   class age sex name / mlf;
   ways 1;
   output out=test;
   run;


options validvarname=any;
ods _all_ close;
ods excel file='c:\temp\test.xlsx';

proc report data=test(rename=(_freq_=' _FREQ_ 'n)) nowd;
   columns _all_;
   define _all_ / display ;
   format _type_ $char3.;
   run;

ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1750209686010.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107891iAB5CEAF14B8B87FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1750209686010.png" alt="Ksharp_0-1750209686010.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 01:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969262#M376804</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-06-18T01:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT variable names that begin and end with an underscore.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969270#M376807</link>
      <description>&lt;P&gt;Or assign a label with extra underscores :&lt;/P&gt;
&lt;PRE&gt;proc report data=test nowd;
   columns _all_;
   define _all_ / display ;
   format _type_ $char3.;
   label _freq_='__freq__' _type_='__type__';
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jun 2025 06:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969270#M376807</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-06-18T06:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT variable names that begin and end with an underscore.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969297#M376817</link>
      <description>&lt;P&gt;Here is the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0ga2q2n39dojun19bt885vxgib5.htm" target="_self"&gt;documentation&lt;/A&gt; that describes the behavior you are seeing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paraSimple"&gt;In LISTING output, if the first and last characters of a heading are one of the following characters, then PROC REPORT uses that character to expand the heading to fill the space over the column or columns. Note that the &amp;lt;&amp;gt; and the &amp;gt;&amp;lt; must be paired.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;− = . _ * + &amp;lt;&amp;gt; &amp;gt;&amp;lt;&lt;/CODE&gt;&lt;/P&gt;
&lt;DIV id="p1ateqxyf7yzden17yx5wesrtj35" class="xisDoc-note"&gt;&lt;STRONG&gt;&lt;SPAN class="xisDoc-noteGenText"&gt;Note:&amp;nbsp;&lt;/SPAN&gt;The use of expanding characters is supported only in LISTING destinations. Therefore, PROC REPORT simply removes the expanding characters when the output is directed to any other destination.&lt;/STRONG&gt; Refer to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A tabindex="0" href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p1n357e2fq6kjkn1ijsu3w97lxl1.htm" target="_blank"&gt;Understanding ODS Destinations&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xisDoc-xrefBookTitle"&gt;SAS Output Delivery System: User’s Guide&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for more information.&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;In your example, you could use PROC PRINT since all variables are defined as Display.&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 18 Jun 2025 11:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969297#M376817</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-06-18T11:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT variable names that begin and end with an underscore.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969312#M376828</link>
      <description>&lt;P&gt;The suggestion by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;to modify the variable label is the most effective work around, renaming is as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;works as long as the variable name is LE 30 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I implemented modifying the label using M_EXPAND_VARLIST.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;817        %let label = %m_expand_varlist(data=test,where=(_name_ like '\_%\_' escape '\'),expr=catx('=',nliteral(_name_),quote(cats('_',_name_,'_'))));
818        %put NOTE: &amp;amp;=label;
NOTE: LABEL=_TYPE_="__TYPE__" _FREQ_="__FREQ__"
819        
820        ods excel file='.\test.xlsx';
821        ods listing close;
822        proc report data=test list;
823           columns _all_;
824           define _all_ / display;
825           attrib _all_ label=' ';
826           label &amp;amp;label;
827           run;
NOTE: Multiple concurrent threads will be used to summarize data.
PROC REPORT DATA=WORK.TEST LS=256 PS=60  SPLIT="/" NOCENTER ;
COLUMN  ( Age Sex Name _TYPE_ _FREQ_ );
 
DEFINE  Age / DISPLAY FORMAT= $12. WIDTH=12    SPACING=2   LEFT "Age" ;
DEFINE  Sex / DISPLAY FORMAT= $1. WIDTH=1     SPACING=2   LEFT "Sex" ;
DEFINE  Name / DISPLAY FORMAT= $8. WIDTH=8     SPACING=2   LEFT "Name" ;
DEFINE  _TYPE_ / DISPLAY FORMAT= $3. WIDTH=3     SPACING=2   LEFT "__TYPE__" ;
DEFINE  _FREQ_ / DISPLAY FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "__FREQ__" ;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro
   m_expand_varlist /*Returns an expanded variable list and optionally creates an indexed data set of variable names*/
      (
         data  = _LAST_,            /*[R]Input data*/
         var   = _ALL_,             /*[R]Variable List expanded*/
         copy  = &amp;amp;var,              /*[O]Copy &amp;amp;VARS to the OUT= data set*/
         where = 1,                 /*[R]Where clause to subset OUT=, useful for selecting by a name suffix e.g. where=_name_ like '%_Status'*/
         expr  = nliteral(&amp;amp;name),   /*[R]An expression that can be used to modify the names in the expanded list*/
         keep  = ,                  /*[O]Keep data set option for DATA=*/
         drop  = ,                  /*[O]Drop data set option for DATA=*/
         rename= ,                  /*[O]Rename data set option for DATA=*/
         out   = work._deleteme_,   /*[O]Output data indexed by _NAME_ and _INDEX_*/
         name  = _NAME_,            /*[R]Name of the variable name variable in the output data set*/
         label = _LABEL_,           /*[R]Name of the variable label variable in the output data set*/
         index = _INDEX_,           /*[R]Name of the variable index variable in the output data set*/
         dlm   = ' '                /*[R]List delimiter*/
      );
   %local m i;
   %let i=&amp;amp;sysindex;
   %let m=&amp;amp;sysmacroname._&amp;amp;i;
   %do %while(%symexist(&amp;amp;m));
      %let i = %eval(&amp;amp;i + 1);
      %let m=&amp;amp;sysmacroname._&amp;amp;i;
      %end;
   /*%put NOTE: &amp;amp;=m is a unique symbol name;*/
   %local rc &amp;amp;m code1 code2 code3 code4 code5;
   %let code1 = %str(options notes=0; proc transpose name=&amp;amp;name label=&amp;amp;label data=&amp;amp;data(obs=0 keep=&amp;amp;keep drop=&amp;amp;drop rename=(&amp;amp;rename)) out=&amp;amp;out(where=(&amp;amp;where)); var &amp;amp;var; copy &amp;amp;copy; run;);
   %let code2 = %str(data &amp;amp;out(index=(&amp;amp;index &amp;amp;name)); set &amp;amp;out; &amp;amp;index+1; run;);
   %let code3 = %str(proc sql noprint; select &amp;amp;expr into :&amp;amp;m separated by &amp;amp;dlm from &amp;amp;out; quit;);
   %if %superq(OUT) eq %str(work._deleteme_) %then %let code4=%str(proc delete data=work._deleteme_; run;);
   %let code5 = %str(options notes=1;);
   %let rc=%sysfunc(dosubl(&amp;amp;code1 &amp;amp;code2 &amp;amp;code3 &amp;amp;code4 &amp;amp;code5));
&amp;amp;&amp;amp;&amp;amp;m.
   %mend m_expand_varlist;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jun 2025 13:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-variable-names-that-begin-and-end-with-an-underscore/m-p/969312#M376828</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-06-18T13:47:02Z</dc:date>
    </item>
  </channel>
</rss>

