<?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: Associate Variables with Labels; Add Labels to Dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/929209#M365619</link>
    <description>&lt;P&gt;Similar approach to the above, but using sql and macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Creating a macro variable "LABELS" that contains variable names and attributed labels*/
proc sql noprint;
	create table have as
		select distinct mnemonic, text 
			from sashelp.webmsg where length(text) eq 55;
	select catx('=', strip(mnemonic), quote(compress(text, '', 'ka'))) into:labels separated by ' ' from have; 
quit;

proc transpose data=have out=have_wide;
	var text;
	id mnemonic;
run; 

/*Applying labels to all variables using macro variable "LABELS"*/
data want;
	set have_wide;
	label &amp;amp;labels;
run; 

proc print data=want label; 
	label; 
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 21 May 2024 22:29:10 GMT</pubDate>
    <dc:creator>A_Kh</dc:creator>
    <dc:date>2024-05-21T22:29:10Z</dc:date>
    <item>
      <title>Associate Variables with Labels; Add Labels to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/928987#M365549</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of variable length limits, etc., I simply renamed all variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i_01&lt;/P&gt;
&lt;P&gt;i_02&lt;/P&gt;
&lt;P&gt;i_03&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But each variable really should be associated with a longer, more descriptive name:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Abc.......&lt;/P&gt;
&lt;P&gt;Def.......&lt;/P&gt;
&lt;P&gt;Ghi.......&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've imported the dataset using the simple variable names.&amp;nbsp; But I'd like to somehow 'import' the longer respective names as 'labels'.&amp;nbsp; Can that be done?&amp;nbsp; If so, how?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Nicholas Kormanik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 07:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/928987#M365549</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2024-05-20T07:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Variables with Labels; Add Labels to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/928990#M365551</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I've imported the dataset using the simple variable names.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;HOW did you import the data. In what format is the source? Please provide a bit more detail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 08:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/928990#M365551</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-20T08:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Variables with Labels; Add Labels to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/929001#M365556</link>
      <description>&lt;P&gt;If you can make a dataset that has the short names in one column and the long names in a second column, then you can proceed as in the program below ... (the long names will serve as label).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;

data short_and_long;
LENGTH varname $ 6 varlabel $ 20; 
varname='Name';   varlabel='xxxxx Name xxxxx';   output;
varname='Sex';    varlabel='xxxxx Sex xxxxx';    output;
varname='Age';    varlabel='xxxxx Age xxxxx';    output;
varname='Height'; varlabel='xxxxx Height xxxxx'; output;
varname='Weight'; varlabel='xxxxx Weight xxxxx'; output;
run;

filename shorlong temp;

data _NULL_;
 set short_and_long end=last;
 file shorlong; 
 if _N_=1 then do;
PUT 'proc datasets library=work NoList NoDetails memtype=data;';
PUT ' modify have;';
 end;
PUT "label " varname "='" varlabel +(-1) "';";
 if last then do;
PUT 'run; QUIT;';
 end;
run;

%INCLUDE shorlong / source2;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 11:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/929001#M365556</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-20T11:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Variables with Labels; Add Labels to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/929209#M365619</link>
      <description>&lt;P&gt;Similar approach to the above, but using sql and macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Creating a macro variable "LABELS" that contains variable names and attributed labels*/
proc sql noprint;
	create table have as
		select distinct mnemonic, text 
			from sashelp.webmsg where length(text) eq 55;
	select catx('=', strip(mnemonic), quote(compress(text, '', 'ka'))) into:labels separated by ' ' from have; 
quit;

proc transpose data=have out=have_wide;
	var text;
	id mnemonic;
run; 

/*Applying labels to all variables using macro variable "LABELS"*/
data want;
	set have_wide;
	label &amp;amp;labels;
run; 

proc print data=want label; 
	label; 
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 May 2024 22:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Associate-Variables-with-Labels-Add-Labels-to-Dataset/m-p/929209#M365619</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2024-05-21T22:29:10Z</dc:date>
    </item>
  </channel>
</rss>

