<?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: Labels to variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799662#M314461</link>
    <description>&lt;P&gt;Generate an series of OLD=NEW pairs and use them in a RENAME statement or RENAME= dataset option. Note that labels can have up to 255 bytes, but names can only have 32.&amp;nbsp; If the labels do not follow normal SAS variable naming rules then you will need to use VALIDVARNAME=ANY system option.&amp;nbsp; You cannot use RENAME to change the case of a name.&amp;nbsp; If you need to do that you will need to do a two step approach where you first change it something else and back to the name with different case for some of the letters.&amp;nbsp; Also make sure that all of the labels are unique.&amp;nbsp; You cannot have two variables with the same name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say your datasets is named MYDATA and it is pointed at by the libref MYLIB.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx('=',nliteral(name),nliteral(substr(label,1,32)))
  into :renames separated by ' '
  from dictionary.columns
  where libname='MYLIB'
    and memname='MYDATA'
    and upcase(name) ne upcase(substr(coalesce(label,name),1,32))
;
quit;

%if (&amp;amp;sqlobs &amp;gt; 0) %then %do;
proc datasets nolist lib=MYLIB;
  modify mydata;
    rename &amp;amp;renames;
  run;
quit;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2022 19:15:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-03-02T19:15:09Z</dc:date>
    <item>
      <title>Labels to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799658#M314458</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;I have a dataset with 250 columns and would like to convert all the sas labels into variable names. How to do it?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 18:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799658#M314458</guid>
      <dc:creator>rajredy7172012</dc:creator>
      <dc:date>2022-03-02T18:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Labels to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799659#M314459</link>
      <description>&lt;P&gt;Are they all applicable as SAS variable names?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 18:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799659#M314459</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-03-02T18:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Labels to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799661#M314460</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303715"&gt;@rajredy7172012&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with 250 columns and would like to convert all the sas labels into variable names. How to do it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why would you want to do that?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 19:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799661#M314460</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-02T19:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Labels to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799662#M314461</link>
      <description>&lt;P&gt;Generate an series of OLD=NEW pairs and use them in a RENAME statement or RENAME= dataset option. Note that labels can have up to 255 bytes, but names can only have 32.&amp;nbsp; If the labels do not follow normal SAS variable naming rules then you will need to use VALIDVARNAME=ANY system option.&amp;nbsp; You cannot use RENAME to change the case of a name.&amp;nbsp; If you need to do that you will need to do a two step approach where you first change it something else and back to the name with different case for some of the letters.&amp;nbsp; Also make sure that all of the labels are unique.&amp;nbsp; You cannot have two variables with the same name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say your datasets is named MYDATA and it is pointed at by the libref MYLIB.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx('=',nliteral(name),nliteral(substr(label,1,32)))
  into :renames separated by ' '
  from dictionary.columns
  where libname='MYLIB'
    and memname='MYDATA'
    and upcase(name) ne upcase(substr(coalesce(label,name),1,32))
;
quit;

%if (&amp;amp;sqlobs &amp;gt; 0) %then %do;
proc datasets nolist lib=MYLIB;
  modify mydata;
    rename &amp;amp;renames;
  run;
quit;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 19:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799662#M314461</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-02T19:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Labels to variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799663#M314462</link>
      <description>&lt;P&gt;Yes, they are all sas variable names.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 19:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Labels-to-variables/m-p/799663#M314462</guid>
      <dc:creator>rajredy7172012</dc:creator>
      <dc:date>2022-03-02T19:11:21Z</dc:date>
    </item>
  </channel>
</rss>

