<?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 rename all variables base on column position? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922641#M363306</link>
    <description>On the surface, this seems like a horrible idea.  You would make your data incredibly difficult to program with, and create the situation where col3 means something different depending on which data set you are working with.&lt;BR /&gt;&lt;BR /&gt;Perhaps you could describe what happens next,, after the names have been changed.  We might be able to suggest a less destructive path to take to your goal.</description>
    <pubDate>Tue, 02 Apr 2024 21:45:42 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2024-04-02T21:45:42Z</dc:date>
    <item>
      <title>How to rename all variables base on column position?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922632#M363301</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have multiple datasets with different col numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to rename each data set as:&lt;/P&gt;
&lt;P&gt;1. 1st col as "label"&lt;/P&gt;
&lt;P&gt;2. 2nd col to last col="Col1" to "Coln";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where n= colum position-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I rename data set without doing rename 1 by 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestion?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 20:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922632#M363301</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-04-02T20:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all variables base on column position?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922635#M363303</link>
      <description>&lt;P&gt;Create a list of variables names(PROC TRANSPOSE) in VARNUM order and create new names using your rule.&amp;nbsp; Note the OBS=0 in the data= options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data heart;
   set sashelp.heart;
   run;
proc transpose data=heart(obs=0) out=vnames;
   var _all_;
   run;

data rename;
   set vnames;
   length newname $32;
   select(_n_);
      when(1)     newname = 'Label';
      otherwise   newname = catx('_','Col',_n_-1);
      end;
   run;

proc print;
   run;
proc sql noprint;
   select catx('=',_name_,newname) into :renlist separated by ' ' 
      from rename;
   quit;
%put NOTE: &amp;amp;=renlist;

proc datasets nolist;
   modify heart;
      rename &amp;amp;renlist;
      run;
   contents data=heart varnum;
   quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Apr 2024 21:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922635#M363303</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-04-02T21:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all variables base on column position?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922636#M363304</link>
      <description>&lt;P&gt;Similar approach to data _null_'s.&amp;nbsp; User PROC CONTENTs to get the metadata on variable number and name, then use PROC SQL to build the macro variable with list of renames:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    proc contents data=sashelp.class out=varinfo (keep=name varnum) ;
2    run ;

NOTE: The data set WORK.VARINFO has 5 observations and 2 variables.

3
4    proc sql noprint ;
5      select cats(name,'=',ifc(varnum=1,"label",cats('Col',varnum-1)))
6      into :renamelist separated by " "
7      from varinfo
8      order by varnum
9     ;
NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause.
10   quit ;

11
12   %put &amp;amp;renamelist;
Name=label Sex=Col1 Age=Col2 Height=Col3 Weight=Col4
&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Apr 2024 21:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922636#M363304</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-04-02T21:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all variables base on column position?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922641#M363306</link>
      <description>On the surface, this seems like a horrible idea.  You would make your data incredibly difficult to program with, and create the situation where col3 means something different depending on which data set you are working with.&lt;BR /&gt;&lt;BR /&gt;Perhaps you could describe what happens next,, after the names have been changed.  We might be able to suggest a less destructive path to take to your goal.</description>
      <pubDate>Tue, 02 Apr 2024 21:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922641#M363306</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-04-02T21:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all variables base on column position?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922709#M363335</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;On the surface, this seems like a horrible idea. You would make your data incredibly difficult to program with, and create the situation where col3 means something different depending on which data set you are working with.&lt;BR /&gt;&lt;BR /&gt;Perhaps you could describe what happens next,, after the names have been changed. We might be able to suggest a less destructive path to take to your goal.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thank you for saying this&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;. I agree completely, HORRIBLE IDEA. Just because you CAN do this, it doesn't mean you SHOULD do this. It seems like extra work for no benefit at all.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/448857"&gt;@stataq&lt;/a&gt;&amp;nbsp;what is the reason you want to do this work? What is the benefit?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 12:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-variables-base-on-column-position/m-p/922709#M363335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-03T12:14:57Z</dc:date>
    </item>
  </channel>
</rss>

