<?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 Can I label variables by another set including the list of variables with their definition? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589969#M168811</link>
    <description>&lt;P&gt;I have one dataset with a list of variables (let's say, AA, BB, CC, .... ZZ). I also have another dataset that includes two columns, one for the list of variables in the former set and the other for their definitions. So, the second set looks like...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VARIABLE_NAME&amp;nbsp; &amp;nbsp;DEFINITION&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of AA&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of BB&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of CC&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of ZZ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if I label variables in the first set using the second set's definition list. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2019 09:37:47 GMT</pubDate>
    <dc:creator>braam</dc:creator>
    <dc:date>2019-09-19T09:37:47Z</dc:date>
    <item>
      <title>Can I label variables by another set including the list of variables with their definition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589969#M168811</link>
      <description>&lt;P&gt;I have one dataset with a list of variables (let's say, AA, BB, CC, .... ZZ). I also have another dataset that includes two columns, one for the list of variables in the former set and the other for their definitions. So, the second set looks like...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VARIABLE_NAME&amp;nbsp; &amp;nbsp;DEFINITION&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of AA&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of BB&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of CC&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Definition of ZZ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if I label variables in the first set using the second set's definition list. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 09:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589969#M168811</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-09-19T09:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can I label variables by another set including the list of variables with their definition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589971#M168812</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try as follows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input A B C;
cards;
1 2 3
4 5 6
;
run;

data labels;
input var $ label $;
cards;
A label_A
B label_B
C label_C
;
run;

data _NULL_;
set labels end=fend;

if _N_=1 then call execute('data want; set have; label ');

call execute(cats(var,'="',label,'"'));

if fend then call execute('; run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 09:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589971#M168812</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-09-19T09:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can I label variables by another set including the list of variables with their definition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589973#M168813</link>
      <description>&lt;P&gt;Alternatively&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input VARIABLE_NAME $ DEFINITION :$20.;
infile datalines dlm=',';
datalines;
AA,Definition of AA
BB,Definition of BB
CC,Definition of CC
;

data two;
AA=1;BB=2;CC=3;
run;

proc sql noprint;
    select cats(VARIABLE_NAME, "='", DEFINITION, "'") into :label separated by ' '
    from one;
run;

%put &amp;amp;label.;

data want;
    set two;
    label &amp;amp;label.;
run;

proc print data=want label;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 09:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589973#M168813</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-19T09:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can I label variables by another set including the list of variables with their definition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589977#M168814</link>
      <description>&lt;P&gt;Or, with either of the two suggested techniques, use PROC DATASETS to assign the labels (and thus avoid potentially time-consuming read and write operations for a large dataset).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example with CALL EXECUTE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data labelds;
input variable_name $ definition :&amp;amp;$40.;
cards;
AA  First label
BB  Second label
;

data have;
AA=1;
BB='X';
run;

data _null_;
if _n_=1 then call execute('proc datasets lib=work nolist; modify have; label');
set labelds end=last;
call execute(variable_name||'='||definition);
if last then call execute('; quit;'); 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 10:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/589977#M168814</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-19T10:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can I label variables by another set including the list of variables with their definition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/590057#M168843</link>
      <description>&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/f18931085f6a0009185c" target="_blank"&gt;https://gist.github.com/statgeek/f18931085f6a0009185c&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Create label data set;
data label_data_set;
length name label $25.;
name="Sex"; label="Gender"; output;
name="height"; label="Height (in)"; output;
name="weight"; label="Weight (lbs)"; output;
run;
 
 
*Create sample dataset to apply label;
data class;
set sashelp.class;
run;
 
 
*Create macro variable that holds label statement;
proc sql noprint;
select catx("=", name, quote(trim(label)))
  into :label_list separated by " "
from label_data_set;
quit;
 
 
*Display macro variable in log;
%put &amp;amp;label_list.;
 
 
*Apply labels without recreating dataset;
proc datasets library=work;
modify class;
label &amp;amp;label_list.;
run;quit;
 
 
*Print the dataset to display new labels;
proc print data=class label noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 15:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/590057#M168843</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-19T15:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Can I label variables by another set including the list of variables with their definition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/590120#M168860</link>
      <description>&lt;P&gt;And another option is to create a program file with the label statements and %include it where wanted instead of permanently changing the labels:&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
   file "c:\folder\subfolder\labelprog.sas";
   set yourdataset;
   str=catx(' ','Label',variable_name,"=",quote(definition),";");
   put str;
run;

proc print data=yourotherdata;
   %include "c:\folder\subfolder\labelprog.sas";
run;&lt;/PRE&gt;
&lt;P&gt;Change your data set names and paths as needed.&lt;/P&gt;
&lt;P&gt;This has minor advantage of you can example the %include file with a text editor and modify any label statement if needed. Or you want to make a slightly modified set of labels for some reason.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 17:08:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-label-variables-by-another-set-including-the-list-of/m-p/590120#M168860</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-19T17:08:41Z</dc:date>
    </item>
  </channel>
</rss>

