<?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: Rename Column name by variablevalue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-Column-name-by-variablevalue/m-p/307285#M65783</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let studybegin_period =MDY(1,1,2015);
%let studyend_period =MDY(12,1,2015) ;

%let studybegin_period =MDY(12,1,2015);
%let studyend_period =MDY(1,1,2015) ;

data HAVE;
  length M1-M12 $1;
run;
         
data _null_;
  length STR $800;  
  do until(MTH=&amp;amp;studyend_period);        
    I+1;
    MTH=intnx('month', &amp;amp;studybegin_period ,ifn(&amp;amp;studybegin_period &amp;lt;&amp;amp;studyend_period, I-1, -I+1));
    STR=catt(STR,' M',I,'=',put(MTH,monyy7.));  
  end;               
  call symputx('rename', STR);
run;

proc datasets; 
  modify HAVE;
  rename &amp;amp;rename.;
quit;
     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: Renaming variable M1 to DEC2015.&lt;BR /&gt;NOTE: Renaming variable M2 to NOV2015.&lt;BR /&gt;NOTE: Renaming variable M3 to OCT2015.&lt;BR /&gt;NOTE: Renaming variable M4 to SEP2015.&lt;BR /&gt;NOTE: Renaming variable M5 to AUG2015.&lt;BR /&gt;NOTE: Renaming variable M6 to JUL2015.&lt;BR /&gt;NOTE: Renaming variable M7 to JUN2015.&lt;BR /&gt;NOTE: Renaming variable M8 to MAY2015.&lt;BR /&gt;NOTE: Renaming variable M9 to APR2015.&lt;BR /&gt;NOTE: Renaming variable M10 to MAR2015.&lt;BR /&gt;NOTE: Renaming variable M11 to FEB2015.&lt;BR /&gt;NOTE: Renaming variable M12 to JAN2015.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2016 02:16:20 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2016-10-26T02:16:20Z</dc:date>
    <item>
      <title>Rename Column name by variablevalue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Column-name-by-variablevalue/m-p/307261#M65779</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I have a macro variable like below&lt;/P&gt;&lt;P&gt;%let studybegin_period =MDY(1,1,2015)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%let studyend_period =MDY(12,1,2015)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a dataset with column names like M1, M2...M12(for 12 months),i need to replace column names with values like&lt;/P&gt;&lt;P&gt;Jan2015,FEB2015....DEC2015.NOTE: the columns increase or decrese depending on the time period i have on the macro variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me know how to go about it.Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 22:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Column-name-by-variablevalue/m-p/307261#M65779</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2016-10-25T22:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Column name by variablevalue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Column-name-by-variablevalue/m-p/307285#M65783</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let studybegin_period =MDY(1,1,2015);
%let studyend_period =MDY(12,1,2015) ;

%let studybegin_period =MDY(12,1,2015);
%let studyend_period =MDY(1,1,2015) ;

data HAVE;
  length M1-M12 $1;
run;
         
data _null_;
  length STR $800;  
  do until(MTH=&amp;amp;studyend_period);        
    I+1;
    MTH=intnx('month', &amp;amp;studybegin_period ,ifn(&amp;amp;studybegin_period &amp;lt;&amp;amp;studyend_period, I-1, -I+1));
    STR=catt(STR,' M',I,'=',put(MTH,monyy7.));  
  end;               
  call symputx('rename', STR);
run;

proc datasets; 
  modify HAVE;
  rename &amp;amp;rename.;
quit;
     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: Renaming variable M1 to DEC2015.&lt;BR /&gt;NOTE: Renaming variable M2 to NOV2015.&lt;BR /&gt;NOTE: Renaming variable M3 to OCT2015.&lt;BR /&gt;NOTE: Renaming variable M4 to SEP2015.&lt;BR /&gt;NOTE: Renaming variable M5 to AUG2015.&lt;BR /&gt;NOTE: Renaming variable M6 to JUL2015.&lt;BR /&gt;NOTE: Renaming variable M7 to JUN2015.&lt;BR /&gt;NOTE: Renaming variable M8 to MAY2015.&lt;BR /&gt;NOTE: Renaming variable M9 to APR2015.&lt;BR /&gt;NOTE: Renaming variable M10 to MAR2015.&lt;BR /&gt;NOTE: Renaming variable M11 to FEB2015.&lt;BR /&gt;NOTE: Renaming variable M12 to JAN2015.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 02:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Column-name-by-variablevalue/m-p/307285#M65783</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-10-26T02:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Column name by variablevalue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Column-name-by-variablevalue/m-p/307290#M65785</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array x{12} m1-m12 (12*1);
run;

%let start=01jan2015;
proc transpose data=have(obs=0) out=temp;
 var m:;
run;
data temp;
 set temp;
 retain n -1;
 n+1;
 name=put(intnx('month',"&amp;amp;start"d,n),monyy7.);
 run;
 data _null_;
  set temp end=last;
  if _n_=1 then 
  call execute('proc datasets library=work nolist nodetails; modify have; rename');
  call execute(catx('=',_name_,name));
  if last then call execute(';quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2016 02:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Column-name-by-variablevalue/m-p/307290#M65785</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-26T02:48:43Z</dc:date>
    </item>
  </channel>
</rss>

