<?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: Displaying both variable name and variable label in the table header in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828479#M327259</link>
    <description>&lt;P&gt;I have the impression that I answered your question. I'm not sure what it is not clear in my question. There is a picture showing exactly what I'm looking for: one row for variable label and one for variable name.&lt;/P&gt;
&lt;P&gt;I've added in the example label just because it was an example for people to quickly test there code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is not to get the expected output. I'm able to get it with data _null_ or macro; Those solutions overcomplicate the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was looking for a smarter approach, if any exist. It could be that there is no possibility.&lt;/P&gt;
&lt;P&gt;I was just asking if someone would be aware of something I'm not aware of. SAS has so many features. It's easy to missout one (many actually).&lt;/P&gt;</description>
    <pubDate>Fri, 12 Aug 2022 15:13:14 GMT</pubDate>
    <dc:creator>xxformat_com</dc:creator>
    <dc:date>2022-08-12T15:13:14Z</dc:date>
    <item>
      <title>Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828229#M327162</link>
      <description>&lt;P&gt;Sometimes, it can be convenient to disply both variable name and variable label in the header of a table.&lt;/P&gt;
&lt;P&gt;I can automate the following proc report using a data _null_.&lt;/P&gt;
&lt;P&gt;But I was wondering on whether there is a smarter way to get the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
    label name   = 'Name Label'
          sex    = 'Sex Label'
          age    = 'Age Label'
          height = 'Height Label'
          weight = 'Weight Label';
    set sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;proc report&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;proc report data=class;
    column ('Name Label'    name)
           ('Sex Label'    sex)
           ('Age Label'    age)
           ('Height Label' height)
           ('Weight Label' weight);
    attrib _all_ label=" ";
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.JPG" style="width: 363px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74347i85AA4F7BEC4D2149/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 09:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828229#M327162</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-08-11T09:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828251#M327169</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sometimes, it can be convenient to disply both variable name and variable label in the header of a table.&lt;/P&gt;
&lt;P&gt;I can automate the following proc report using a data _null_.&lt;/P&gt;
&lt;P&gt;But I was wondering on whether there is a smarter way to get the result.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Smarter perhaps — but initially more work: you can read the variable names and labels from either PROC CONTENTS output or from the dictionary tables, and then create a macro that essentially creates the LABEL statement that you have.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I will get you started using data set SASHELP.GAS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select name, coalesce(label,name) into :names separated by ' ',:labels separated by '~'
    from dictionary.columns 
    where libname='SASHELP' and memname='GAS' 
    order by varnum;
quit;

%put &amp;amp;=names;
%put &amp;amp;=labels;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you have macro variables containing the variable names and the variable labels. From there, you would have to create macro code to generate the LABEL statement you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 12:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828251#M327169</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-11T12:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828253#M327170</link>
      <description>&lt;P&gt;If you need the label to display the name then include the name in the label and just use the LABEL as the header.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  set sashelp.class;
  label name   = 'Name Label (NAME)'
        sex    = 'Sex Label (SEX)'
        age    = 'Age Label (AGE)'
        height = 'Height Label (HEIGHT)'
        weight = 'Weight Label (WEIGHT)'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the down stream code does not need anything special.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1660222051148.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74355i00B0435378348E90/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1660222051148.png" alt="Tom_0-1660222051148.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can automate the addition of the name to the label.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  set sashelp.class;
  label name   = 'Name Label'
        sex    = 'Sex Label'
        age    = 'Age Label'
        height = 'Height Label'
        weight = 'Weight Label'
   ;
run;

proc transpose data=class(obs=0) out=names;
  var _all_;
run;

filename code temp;
data names;
  length varnum 8 _name_ $32 _label_ $256 ;
  set names ;
  varnum+1;
  file code ;
  _label_=coalescec(_label_,_name_);
  _label_=catx(' ',_label_,cats('(',upcase(_name_),')'));
  put 'label ' _name_ '=' _label_ :$quote. ';';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now either run the generated LABEL statements in a DATA step or PROC DATASETS step to change the attached labels.&lt;/P&gt;
&lt;P&gt;Or include the LABEL statements into the PROC step that is using the data.&lt;/P&gt;
&lt;PRE&gt;1206  proc report data=class ;
1207  %include code / source2;
NOTE: %INCLUDE (level 1) file CODE is file ...\#LN00063.
1208 +label Name ="Name Label (NAME)" ;
1209 +label Sex ="Sex Label (SEX)" ;
1210 +label Age ="Age Label (AGE)" ;
1211 +label Height ="Height Label (HEIGHT)" ;
1212 +label Weight ="Weight Label (WEIGHT)" ;
NOTE: %INCLUDE (level 1) ending.
1213  run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 13:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828253#M327170</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-11T13:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828255#M327171</link>
      <description>&lt;P&gt;You could make a macro variable to contain that statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
    set sashelp.class;
    label name   = 'Name Label'
          sex    = 'Sex Label'
          age    = 'Age Label'
          height = 'Height Label'
          weight = 'Weight Label';
run;

proc sql noprint;
select catx(' ','("',label,'"',name,')') into :header separated by ' '
 from dictionary.columns
  where libname='WORK' and memname='CLASS';
quit;


proc report data=class nowd;
column &amp;amp;header ;
attrib _all_ label=" ";
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Aug 2022 12:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828255#M327171</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-11T12:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828257#M327172</link>
      <description>&lt;P&gt;Reading the other replies, I now wonder if your question is: how to do this so that the variable name is &lt;FONT color="#FF0000"&gt;always&lt;/FONT&gt; followed by the word Label; or if you want something more general where there are actual labels that are different than the variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please clarify this.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 12:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828257#M327172</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-11T12:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828368#M327224</link>
      <description>You're right. My original question was not about adding the variable name in brackets after the variable. But it is another interesting approach for providing both variable label and name, I hadn't thought about. I take it as a nice tip as it makes the code light.&lt;BR /&gt;&lt;BR /&gt;My actual question was to get one row for the variable label and another one for the variable name without having to automate (i.e. without data _null_ or without macro language).</description>
      <pubDate>Thu, 11 Aug 2022 21:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828368#M327224</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-08-11T21:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828385#M327232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;You're right. My original question was not about adding the variable name in brackets after the variable. But it is another interesting approach for providing both variable label and name, I hadn't thought about. I take it as a nice tip as it makes the code light.&lt;BR /&gt;&lt;BR /&gt;My actual question was to get one row for the variable label and another one for the variable name without having to automate (i.e. without data _null_ or without macro language).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have to say that you didn't answer my question. And so nothing has been cleared up. Your original code took the variable name and appended the word "Label" and this is now the label you want to use. Is that all you are asking to do, append the word "Label" after the variable name, or do you want to use the actual variable labels? For example, in SASHELP.GAS where three of the variables in the data set have a label attached to it, the variable CPRATIO has label "Compression Ratio", and so do you want "Compression Ratio" to appear in your PROC REPORT output or do you want "CPRATIO Label" to appear in your PROC REPORT output? Please make this clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want an answer without macros and without DATA _NULL_ — why? Why eliminate valid tools to get the job done?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 22:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828385#M327232</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-11T22:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828479#M327259</link>
      <description>&lt;P&gt;I have the impression that I answered your question. I'm not sure what it is not clear in my question. There is a picture showing exactly what I'm looking for: one row for variable label and one for variable name.&lt;/P&gt;
&lt;P&gt;I've added in the example label just because it was an example for people to quickly test there code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is not to get the expected output. I'm able to get it with data _null_ or macro; Those solutions overcomplicate the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was looking for a smarter approach, if any exist. It could be that there is no possibility.&lt;/P&gt;
&lt;P&gt;I was just asking if someone would be aware of something I'm not aware of. SAS has so many features. It's easy to missout one (many actually).&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 15:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828479#M327259</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-08-12T15:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828482#M327261</link>
      <description>&lt;P&gt;Ok, we're not communicating, and I'll let other people who apparently do understand you help.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 15:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828482#M327261</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-12T15:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828542#M327279</link>
      <description>&lt;P&gt;As others proposed I believe the most generic solution that will work with any procedure creating a report would be to add the column name to the label.&lt;/P&gt;
&lt;P&gt;If you don't want to change the labels permanently on the source table then at least some of the PROC's allow for a label statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s code below a sample how this could work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
    set sashelp.class;
    label name   = 'Name Label'
          sex    = 'Sex Label'
          age    = 'Age Label'
          height = 'Height Label'
          weight = 'Weight Label';
run;

proc sql noprint;
  select catt(name,"='",label," (",name,")'") into :label  separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='CLASS';
quit;
%put &amp;amp;label;

proc report data=class nowd;
  column _all_ ;
  label &amp;amp;label;
run;

proc print data=class label;
  label &amp;amp;label;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2022 02:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828542#M327279</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-08-13T02:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828575#M327296</link>
      <description>&lt;P&gt;This solution does not answer exactly my question but allows at least to have two lines in a row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
    label name   = 'Name Label*Name'
          sex    = 'Sex Label*Sex'
          age    = 'Age Label*Age'
          height = 'Height Label*Height'
          weight = 'Weight Label*Weight';
    set sashelp.class;
run;

proc report data=class split='*';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm still investing.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2022 19:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828575#M327296</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-08-13T19:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying both variable name and variable label in the table header</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828586#M327306</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;If you want the exact layout as per your sample then use the code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;proposed.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2022 22:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-both-variable-name-and-variable-label-in-the-table/m-p/828586#M327306</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-08-13T22:29:31Z</dc:date>
    </item>
  </channel>
</rss>

