<?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 add a row with column enumaration in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-add-a-row-with-column-enumaration/m-p/842517#M26006</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280054"&gt;@mattj&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear Group,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add a row just below column headers with individual number. I'd rather do it automatically instead of manually editing title in each column statement - columns number may change. It would very much help me to refer to the columns during the discussion since some of them may have a lengthy description and reuse the numbers in multipage tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The example of the desired outcome is attached.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-11-03 at 15.05.30.png" style="width: 377px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76924i2D27A6E34A2386B0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-11-03 at 15.05.30.png" alt="Screenshot 2022-11-03 at 15.05.30.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Matthew&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I do something similar where the first header row is variable LABEL and the second row is the variable name.&amp;nbsp; That format is useful when making EXCEL output that you might want to read back into SAS.&amp;nbsp; &amp;nbsp;Here are examples that might be helpful.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vars=Cylinders Horsepower MPG_City MPG_Highway Weight Wheelbase Length Make Model Type Origin DriveTrain MSRP Invoice EngineSize;
options formchar="|----|+|---+=|-/\&amp;lt;&amp;gt;*";
proc report data=sashelp.cars(obs=10) nowd list headline;
   column %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ','(',quote(strip(coalesceC(_label_,_name_))),quote('--'),_name_,')'));
   label %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ',_name_,'=',quote(cats('(',_index_,')'))));
   define _all_ / display;
   run;


proc report data=sashelp.cars(obs=10) nowd list headline;
   column %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ','(',quote(strip(coalesceC(_label_,_name_))),quote('--'),_name_,')'));
   attrib _all_ label=' ';
   define _all_ / display;
   run;


proc report data=sashelp.cars(obs=10) nowd list headline;
   column %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ','(',quote(cats('(',_index_,')')),quote('--'),_name_,')'));
   /*label %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ',_name_,'=',quote(cats('(',_index_,')'))));*/
   attrib _all_ label=' ';
   define _all_ / display;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76943i0EFB4AA649E21EB0/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;P&gt;The macro M_EXPAND_VARLIST&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>Fri, 04 Nov 2022 14:38:16 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2022-11-04T14:38:16Z</dc:date>
    <item>
      <title>PROC REPORT add a row with column enumaration</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-add-a-row-with-column-enumaration/m-p/842411#M26003</link>
      <description>&lt;P&gt;Dear Group,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to add a row just below column headers with individual number. I'd rather do it automatically instead of manually editing title in each column statement - columns number may change. It would very much help me to refer to the columns during the discussion since some of them may have a lengthy description and reuse the numbers in multipage tables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example of the desired outcome is attached.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-11-03 at 15.05.30.png" style="width: 377px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76924i2D27A6E34A2386B0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-11-03 at 15.05.30.png" alt="Screenshot 2022-11-03 at 15.05.30.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Matthew&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 21:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-add-a-row-with-column-enumaration/m-p/842411#M26003</guid>
      <dc:creator>mattj</dc:creator>
      <dc:date>2022-11-03T21:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT add a row with column enumaration</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-add-a-row-with-column-enumaration/m-p/842517#M26006</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280054"&gt;@mattj&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear Group,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add a row just below column headers with individual number. I'd rather do it automatically instead of manually editing title in each column statement - columns number may change. It would very much help me to refer to the columns during the discussion since some of them may have a lengthy description and reuse the numbers in multipage tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The example of the desired outcome is attached.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-11-03 at 15.05.30.png" style="width: 377px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76924i2D27A6E34A2386B0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-11-03 at 15.05.30.png" alt="Screenshot 2022-11-03 at 15.05.30.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Matthew&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I do something similar where the first header row is variable LABEL and the second row is the variable name.&amp;nbsp; That format is useful when making EXCEL output that you might want to read back into SAS.&amp;nbsp; &amp;nbsp;Here are examples that might be helpful.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vars=Cylinders Horsepower MPG_City MPG_Highway Weight Wheelbase Length Make Model Type Origin DriveTrain MSRP Invoice EngineSize;
options formchar="|----|+|---+=|-/\&amp;lt;&amp;gt;*";
proc report data=sashelp.cars(obs=10) nowd list headline;
   column %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ','(',quote(strip(coalesceC(_label_,_name_))),quote('--'),_name_,')'));
   label %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ',_name_,'=',quote(cats('(',_index_,')'))));
   define _all_ / display;
   run;


proc report data=sashelp.cars(obs=10) nowd list headline;
   column %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ','(',quote(strip(coalesceC(_label_,_name_))),quote('--'),_name_,')'));
   attrib _all_ label=' ';
   define _all_ / display;
   run;


proc report data=sashelp.cars(obs=10) nowd list headline;
   column %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ','(',quote(cats('(',_index_,')')),quote('--'),_name_,')'));
   /*label %m_expand_varlist(data=sashelp.cars,var=&amp;amp;vars,expr=catx(' ',_name_,'=',quote(cats('(',_index_,')'))));*/
   attrib _all_ label=' ';
   define _all_ / display;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76943i0EFB4AA649E21EB0/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;P&gt;The macro M_EXPAND_VARLIST&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>Fri, 04 Nov 2022 14:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-add-a-row-with-column-enumaration/m-p/842517#M26006</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2022-11-04T14:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT add a row with column enumaration</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-add-a-row-with-column-enumaration/m-p/842648#M26018</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;


proc sql noprint;
select cats(name,'="(',varnum,')"'),catx(' ','("',name,'"',name,')')
 into :labels separated by ' ',:headers separated by ' '
 from dictionary.columns
  where libname='WORK' and memname='HAVE';
quit;

ods rtf file='c:\temp\temp.rtf' style=minimal;
proc report data=have nowd;
label &amp;amp;labels.;
column &amp;amp;headers.;
run;
ods rtf 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-1667644391943.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76974i88CC38BF6D9C9E1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1667644391943.png" alt="Ksharp_0-1667644391943.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 10:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-add-a-row-with-column-enumaration/m-p/842648#M26018</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-05T10:33:18Z</dc:date>
    </item>
  </channel>
</rss>

