<?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 columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538617#M148287</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;



proc transpose data=have(obs=0) out=temp;
var _all_;
run;
data temp;
 set temp;
 length new $ 40;
 if _n_=1 then new='id    ';
  else if _n_=2 then new='city    ';
   else if _n_=3 then new='country    ';
run;
proc sql noprint;
select catx('=',_name_,new) into : rename separated by ' '
 from temp
  where new is not missing;
quit;

%put &amp;amp;rename ;
proc datasets library=work nolist nodetails;
modify have;
rename &amp;amp;rename ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Feb 2019 12:45:18 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-02-26T12:45:18Z</dc:date>
    <item>
      <title>Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538558#M148267</link>
      <description>Hello&lt;BR /&gt;How can I rename columns names of was data set by the following way:&lt;BR /&gt;Rename 1st column to "Id"&lt;BR /&gt;Rename 2nd column to "City"&lt;BR /&gt;Rename 3rd column to "country ".&lt;BR /&gt;As you can see I don't know the original names so i cannot use Rename=old_name=new_name"</description>
      <pubDate>Tue, 26 Feb 2019 05:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538558#M148267</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-02-26T05:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538561#M148268</link>
      <description>The issue is that the original fields names are different every day but the desired fields names is fixed</description>
      <pubDate>Tue, 26 Feb 2019 05:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538561#M148268</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-02-26T05:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538566#M148271</link>
      <description>&lt;P&gt;Do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
var1=''; var2=''; var3='';
run;

proc sql;
   create table want as
   select 1 as Id, 
          2 as City,
          3 as Country
   from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Feb 2019 06:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538566#M148271</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-26T06:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538579#M148278</link>
      <description>&lt;P&gt;In sashelp.vcolumn all variables and their position are stored. By querying that view, call execute can be used to code a proc dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.class;
   set sashelp.class;
run;

proc format;
   value NewNames
      1 = 'Id'
      2 = 'City'
      3 = 'Country'
   ;
run;

data _null_;
   set sashelp.vcolumn(where=(LibName = 'WORK' and MemName = 'CLASS' and Varnum &amp;lt;= 3)) end=almostDone;

   if _n_ = 1 then do;
      call execute('proc datasets library=work nolist;');
      call execute('modify CLASS;');
   end;

   call execute(catx(' ', 'rename', Name, '=', put(Varnum, NewNames.), ';'));

   if almostDone then do;
      call execute('quit;');
   end;   
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 07:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538579#M148278</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-26T07:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538588#M148281</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;As you can see I don't know the original names" - and therein lies your problem.&amp;nbsp; Why do&amp;nbsp;&lt;STRONG&gt;You&lt;/STRONG&gt; not know&amp;nbsp;&lt;STRONG&gt;Your&amp;nbsp;&lt;/STRONG&gt;data?&amp;nbsp; Where is your import agreement, or data structure agreement - the fundamental basis of using any data is to understand what it contains and how.&amp;nbsp; If you don't know that you may as well go ahead and delete it as it will provide you nothing but work.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 08:25:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538588#M148281</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-26T08:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538617#M148287</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;



proc transpose data=have(obs=0) out=temp;
var _all_;
run;
data temp;
 set temp;
 length new $ 40;
 if _n_=1 then new='id    ';
  else if _n_=2 then new='city    ';
   else if _n_=3 then new='country    ';
run;
proc sql noprint;
select catx('=',_name_,new) into : rename separated by ' '
 from temp
  where new is not missing;
quit;

%put &amp;amp;rename ;
proc datasets library=work nolist nodetails;
modify have;
rename &amp;amp;rename ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Feb 2019 12:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538617#M148287</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-02-26T12:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538885#M148394</link>
      <description>&lt;P&gt;This is not &amp;nbsp;a good solution.&lt;/P&gt;
&lt;P&gt;Please see the example below.&lt;/P&gt;
&lt;P&gt;As you can see in the data sets : want_a &amp;nbsp;want_b &amp;nbsp;want_c &amp;nbsp;, it didn't read the data well&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data a;
input xx1 xx2 xx3;
cards;
1 11 111
2 22 222
3 33 333
;
Run;

Data b;
input yy1 yy2 yy3;
cards;
1 11 111
2 22 222
3 33 333
;
Run;

Data c;
input x1 x2 y3 y4;
cards;
1 11 111 9
2 22 222 9
3 33 333 9
;
Run;


/**************Way1*****************/
/**************Way1*****************/
/**************Way1*****************/
/**************Way1*****************/
proc sql;
   create table want_a as
   select 1 as X1, 
          2 as X2,
          3 as X3
   from a;
quit;

proc sql;
   create table want_b as
   select 1 as X1, 
          2 as X2,
          3 as X3
   from b;
quit;

proc sql;
   create table want_c as
   select 1 as X1, 
          2 as X2,
          3 as X3
   from c;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 04:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538885#M148394</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-02-27T04:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538887#M148396</link>
      <description>&lt;P&gt;Great solution!!!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 04:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns/m-p/538887#M148396</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-02-27T04:48:10Z</dc:date>
    </item>
  </channel>
</rss>

