<?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: how to set maximum length for variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275120#M54975</link>
    <description>Hi ballardw,&lt;BR /&gt;Is there a way to do in a more efficient (dynamic) way rather than renaming? Sometimes I will not know the name and number of the variable.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
    <pubDate>Fri, 03 Jun 2016 21:07:38 GMT</pubDate>
    <dc:creator>mlogan</dc:creator>
    <dc:date>2016-06-03T21:07:38Z</dc:date>
    <item>
      <title>how to set maximum length for variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275101#M54970</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;Is there a way to set maximum length of variable name in dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I have the following variable:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name1_1_sdfgasd &amp;nbsp; &amp;nbsp; &amp;nbsp;Name_1_2_sdfsklj &amp;nbsp; &amp;nbsp;Name_1_3_asdfasd &amp;nbsp;(in this example first 7 character is unique)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I want them as:&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Name1_1 &amp;nbsp; &amp;nbsp;Name_1_2 &amp;nbsp; Name_1_3&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 19:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275101#M54970</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-06-03T19:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to set maximum length for variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275104#M54971</link>
      <description>&lt;P&gt;SAS datasets have a design limit of 32 characters maximum.&lt;/P&gt;
&lt;P&gt;If you have imported data that yielded names that you do not want there are a number of ways to rename the variables. Manual method would be to open the column view of the Dataset in the SAS Explorer, click on the name and rename.&lt;/P&gt;
&lt;P&gt;Other methods involve using Proc Datasets or a rename statement in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; rename Name1_1_sdfgasd&amp;nbsp;=Name1_1 &amp;nbsp;Name_1_2_sdfsklj&amp;nbsp;= &amp;nbsp;Name_1_2 &amp;lt;etc&amp;gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 20:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275104#M54971</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-03T20:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to set maximum length for variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275120#M54975</link>
      <description>Hi ballardw,&lt;BR /&gt;Is there a way to do in a more efficient (dynamic) way rather than renaming? Sometimes I will not know the name and number of the variable.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Fri, 03 Jun 2016 21:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275120#M54975</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-06-03T21:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to set maximum length for variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275128#M54977</link>
      <description>&lt;P&gt;I am not sure what "dynamic" might mean in this sense. Can you provide a rule that will work every time and be unambiguous? Your example looks like "truncate at the last underscore following a digit". But does that work if you get a variable of Name_1_4_pd3_abc&lt;/P&gt;
&lt;P&gt;and you want to truncate at the 4?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would look into where these names are coming from in the first place. I suspect they are from Proc Import reading a file with long headers. If the source files were of a common layout but are just getting headers changed such as Var_1_March in one file and Var_1_April in the next but basically should just be Var_1 then I would look into my import procedure to read with the correct names and other properties.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The alternate approach would have to be along the lines of 1) get the current names (Proc Contents or from sashelp.vcolumns) in a data set, 2) use appropriate rules to create a new variable with the modified name and 3) use the results to rename the variables (proc datasets or a rename statement).&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 22:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275128#M54977</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-03T22:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to set maximum length for variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275153#M54991</link>
      <description>&lt;PRE&gt;
You can rename them all the time.


data have;
input Name1_1_sdfgasd      Name_1_2_sdfsklj    Name_1_3_asdfasd   ;
cards;  
100    293       284
100    291       284
;
run;
proc transpose data=have(obs=0) out=temp;
 var _all_;
run;
data temp;
 set temp;
 length name $ 32;
 name=substr(_name_,1,findc(_name_,'_','b')-1);
run;
proc sql noprint;
 select catx('=',_name_,name) into : list separated by ' '
  from temp;
quit;
proc datasets library=work nodetails nolist;
 modify have;
 rename &amp;amp;list ;
quit;
 

&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jun 2016 04:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-maximum-length-for-variable-name/m-p/275153#M54991</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-04T04:23:59Z</dc:date>
    </item>
  </channel>
</rss>

