<?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: RE label multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873335#M345057</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One wat to get around the potential "too long" scenario would be writing the code into a separate file, and then running the newly created file&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Basically take&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;original code and re-arrange it slightly&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dyncode temp;

data _null_;
	length str $300;
	file dyncode lrecle=300;
	put 'proc datasets nolist lib=work;' ;
	put +3 'modify have ;' ;
	put +3 'label ';
	do until(eof);
		SET sashelp.vcolumn(where=(libname='WORK' and memname='HAVE' and upcase(substr(name,1,3)) in ('VAR','NUM') and label ne ' ')) 
			end=eof;
		str = catx('=',nliteral(name),quote(catx(' ',substr(name,1,3),label),"'"));
		put +6 str;
	end;	
	put +3 ';';
	put 'run; quit; ';
run;
%include dyncode;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The generated code should be a single Proc Datasets step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this help&lt;/P&gt;</description>
    <pubDate>Tue, 02 May 2023 11:06:06 GMT</pubDate>
    <dc:creator>AhmedAl_Attar</dc:creator>
    <dc:date>2023-05-02T11:06:06Z</dc:date>
    <item>
      <title>RE label multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873287#M345032</link>
      <description>I have multiple variables as var1, var2,…var78, num1,num2 etc.&lt;BR /&gt;They all have labels. I want to change the labels by adding 3 strings : for example, for all variables with start var then add VAR at the beginning of the labels if num1 etc all variables with start num then add NUM at the beginning of the all labels. How can I do that? Thank you.</description>
      <pubDate>Mon, 01 May 2023 23:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873287#M345032</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-05-01T23:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: RE label multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873294#M345036</link>
      <description>&lt;P&gt;If the number of variables is small (or more accurately the total length of all of the new labels is small) enough to fit into a macro variable just use an SQL query to generate the code needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx('=',nliteral(name),quote(catx(' ',substr(name,1,3),label),"'"))
  into :labels separated by ' '
  where libname = 'WORK'
    and memname='HAVE'
    and upcase(substr(name,1,3)) in ('VAR','NUM')
    and label ne ' '
  ;
quit;
proc datasets nolist lib=work;
  modify have ;
    label &amp;amp;labels;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 May 2023 02:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873294#M345036</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-02T02:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: RE label multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873331#M345055</link>
      <description>If too long—can we stratify by var variables and num variables? How can do that? Thank you so much.</description>
      <pubDate>Tue, 02 May 2023 10:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873331#M345055</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-05-02T10:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: RE label multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873335#M345057</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One wat to get around the potential "too long" scenario would be writing the code into a separate file, and then running the newly created file&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Basically take&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;original code and re-arrange it slightly&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dyncode temp;

data _null_;
	length str $300;
	file dyncode lrecle=300;
	put 'proc datasets nolist lib=work;' ;
	put +3 'modify have ;' ;
	put +3 'label ';
	do until(eof);
		SET sashelp.vcolumn(where=(libname='WORK' and memname='HAVE' and upcase(substr(name,1,3)) in ('VAR','NUM') and label ne ' ')) 
			end=eof;
		str = catx('=',nliteral(name),quote(catx(' ',substr(name,1,3),label),"'"));
		put +6 str;
	end;	
	put +3 ';';
	put 'run; quit; ';
run;
%include dyncode;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The generated code should be a single Proc Datasets step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this help&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 11:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873335#M345057</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-05-02T11:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: RE label multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873343#M345060</link>
      <description>&lt;P&gt;You already have a solution, but just for fun, an alternative one with proc transpose and call execute():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  retain var1 - var78 "abc" num1 - num20 0 A B C D E F G "xxx";
  ATTRIB
    var1 -- var78 label= "some label"
    num1 -- num20 label= "other lable"
    A -- G        label= 'different variables'
  ;
run;

proc transpose data=have(obs=0) out=temp;
  var var: num:;
run;
data _null_;
  call execute('
    proc datasets nolist lib=work;
      modify have ;
        label');
  do until(eof);
    set temp end=eof;
    call execute(cat(_NAME_,"='",substr(_NAME_,1,3)," ",_LABEL_,"'"));
  end;

  call execute(';run;quit;');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 12:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873343#M345060</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-02T12:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: RE label multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873349#M345065</link>
      <description>It gives an error that no from statement and no found name variable</description>
      <pubDate>Tue, 02 May 2023 12:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873349#M345065</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-05-02T12:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: RE label multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873352#M345067</link>
      <description>insert&lt;BR /&gt;FROM dictionary.columns&lt;BR /&gt;above &lt;BR /&gt;Where libname = 'WORK'</description>
      <pubDate>Tue, 02 May 2023 12:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-label-multiple-variables/m-p/873352#M345067</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-05-02T12:32:32Z</dc:date>
    </item>
  </channel>
</rss>

