<?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 Rename List of Columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208992#M38805</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset called TEMP and has column names as VAR1, VAR2, VAR3, ....., VAR300.&lt;/P&gt;&lt;P&gt;I would like to rename VAR1 to CARNUM, VAR2 to MARK, AND VAR3 ~ VAR300 in Y4-M2 format.&lt;/P&gt;&lt;P&gt;VAR3 = 2000-01, VAR4 = 2000-02, VAR5 = 2000-03, VAR6 = 2000-04, VAR7 = 2000-05, VAR8 = 2000-06, .... VAR15 = 2001-01, VAR16 = 2001-12, and ect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way that I can use a do loop to rename VAR3 ~ VAR 300?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Jun 2015 06:51:57 GMT</pubDate>
    <dc:creator>Lindsey</dc:creator>
    <dc:date>2015-06-18T06:51:57Z</dc:date>
    <item>
      <title>Rename List of Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208992#M38805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset called TEMP and has column names as VAR1, VAR2, VAR3, ....., VAR300.&lt;/P&gt;&lt;P&gt;I would like to rename VAR1 to CARNUM, VAR2 to MARK, AND VAR3 ~ VAR300 in Y4-M2 format.&lt;/P&gt;&lt;P&gt;VAR3 = 2000-01, VAR4 = 2000-02, VAR5 = 2000-03, VAR6 = 2000-04, VAR7 = 2000-05, VAR8 = 2000-06, .... VAR15 = 2001-01, VAR16 = 2001-12, and ect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way that I can use a do loop to rename VAR3 ~ VAR 300?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 06:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208992#M38805</guid>
      <dc:creator>Lindsey</dc:creator>
      <dc:date>2015-06-18T06:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Rename List of Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208993#M38806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a template I've been using for a while, you'll have to play around with the variable names that you want changed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select cats(name,'=','OLD_',name)&lt;/P&gt;&lt;P&gt;into :prefixlist&lt;/P&gt;&lt;P&gt;separated by ' '&lt;/P&gt;&lt;P&gt;from dictionary.columns&lt;/P&gt;&lt;P&gt;where libname = 'MDJ' and lowcase(memname) = 'old_lgd_s1_base';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data mdj.old_lgd_s1_base(rename=(&amp;amp;prefixlist));&lt;/P&gt;&lt;P&gt;set mdj.old_lgd_s1_base;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 12:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208993#M38806</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-18T12:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Rename List of Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208994#M38807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Make a map table Like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;VAR1&amp;nbsp;&amp;nbsp; CARNUM&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;VAR2&amp;nbsp;&amp;nbsp; MARK&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;VAR3&amp;nbsp;&amp;nbsp; 2000-01&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Then call execute + proc datasets &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 12:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208994#M38807</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-06-18T12:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rename List of Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208995#M38808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you actually want the variable name to start with a digit and have a - (dash) not at underscore you will have to use the '2002-01'n form to use non-standard variable names.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 14:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208995#M38808</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-06-18T14:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Rename List of Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208996#M38809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can have a macro write out all the PROC DATASETS....RENAME... text to an external file, then %include it....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&amp;nbsp;&amp;nbsp; *create test data set ;&lt;BR /&gt;array v {*} var1-var300;&lt;BR /&gt;do x = 1 to 3;&lt;BR /&gt;do i = 1 to dim(v);&lt;BR /&gt; v{i}=ranuni(0);&lt;BR /&gt;end; output; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* Macro to write the variable name-pairs to an external file.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */ &lt;BR /&gt;%macro r;&lt;BR /&gt;%let x = 2;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%do yr4 = 2000 %to 2025;&lt;BR /&gt; %do mth = 1 %to 9;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; %let x = %eval(&amp;amp;x+1);&lt;BR /&gt;&amp;nbsp; %let yrmo = _&amp;amp;yr4._0&amp;amp;mth;&lt;BR /&gt;&amp;nbsp; %let var = VAR&amp;amp;x;&lt;BR /&gt;&amp;nbsp; %if %eval(&amp;amp;x &amp;lt;= 300) %then %do;&lt;BR /&gt;&amp;nbsp; put @1 "&amp;nbsp; &amp;amp;var&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp; &amp;amp;yrmo ";&amp;nbsp; %end;&lt;BR /&gt; %end;&lt;BR /&gt; %do mth = 10 %to 12;&lt;BR /&gt;&amp;nbsp; %let x = %eval(&amp;amp;x+1);&lt;BR /&gt;&amp;nbsp; %let yrmo = _&amp;amp;yr4._&amp;amp;mth;&lt;BR /&gt;&amp;nbsp; %let var = VAR&amp;amp;x;&lt;BR /&gt;&amp;nbsp; %if %eval(&amp;amp;x &amp;lt;= 300) %then %do;&lt;BR /&gt;&amp;nbsp; put @1 "&amp;nbsp; &amp;amp;var&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp; &amp;amp;yrmo" ; %end;&lt;BR /&gt; %end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend r;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&amp;nbsp;&amp;nbsp; *put PROC DATASETS..w/RENAME statement to external file ;&lt;BR /&gt;set temp;&lt;BR /&gt;file "C:\junk\rename.txt";&lt;BR /&gt;if _n_ = 1 then&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt; put @1 "Proc DATASETS lib=work;" /&lt;BR /&gt;&amp;nbsp; @1 "Modify TEMP; " / &lt;BR /&gt;&amp;nbsp; @1 "RENAME&amp;nbsp; "&amp;nbsp;&amp;nbsp; ; &lt;/P&gt;&lt;P&gt;%r&lt;/P&gt;&lt;P&gt;put @1 " ;&amp;nbsp; quit; ";&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%include "C:\junk\rename.txt" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: I used standard SAS variable names - added some underscores. (See ballardW's comments).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 16:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208996#M38809</guid>
      <dc:creator>Tommywhosc</dc:creator>
      <dc:date>2015-06-18T16:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Rename List of Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208997#M38810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't tested it yet, but after the data step to rename the first two variables, you could try something like the following rename macro.&amp;nbsp; Hope this helps!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data old;&lt;/P&gt;&lt;P&gt;set temp (rename=(VAR1=CARNUM VAR2=MARK));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro rename(n);&lt;/P&gt;&lt;P&gt;%let year=2000;&lt;/P&gt;&lt;P&gt;%let month=01;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=3 %to &amp;amp;n;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set old (rename=(VAR&amp;amp;i="&amp;amp;year-&amp;amp;month"n));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;month&amp;lt;09 %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let month=0%eval(&amp;amp;month+1); %end;&lt;/P&gt;&lt;P&gt;%else %if &amp;amp;month&amp;lt;12 %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let month=%eval(&amp;amp;month+1); %end;&lt;/P&gt;&lt;P&gt;%else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let month=01;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let year=%eval(&amp;amp;year+1); %end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%rename(300)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 20:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208997#M38810</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-06-18T20:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rename List of Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208998#M38811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Step1 - create mapping table&lt;/P&gt;&lt;P&gt;Step 2 - create rename statement &lt;/P&gt;&lt;P&gt;Step 3 - rename&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's a worked example in this question:&lt;/P&gt;&lt;P&gt;&lt;A __default_attr="267462" __jive_macro_name="message" class="jive_macro jive_macro_message" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 20:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-List-of-Columns/m-p/208998#M38811</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-06-18T20:41:41Z</dc:date>
    </item>
  </channel>
</rss>

