<?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 the column names of a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496661#M131397</link>
    <description>&lt;P&gt;If you are familiar with hashes. There is away using Hashes as it accepts literal expressions. Looping num and char arrays and feeding into hash obj at run time hash.definekey(' ')&amp;nbsp; in a loop. Hash guru PD aka Paul Dorfman who is very busy now and will be here in a couple of weeks or less&amp;nbsp; has demonstrated alike in many of his papers. You could output the hash renamed contents to a dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not recommending, however it's nice to bring some awareness while I got lucky to receive&amp;nbsp;privileges from PD on a personal level&lt;/P&gt;</description>
    <pubDate>Tue, 18 Sep 2018 18:13:17 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-18T18:13:17Z</dc:date>
    <item>
      <title>How to rename all the column names of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496616#M131379</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; I would like to request your help in guiding me in my attempt to rename all the columns in a SAS dataset. I have gone through different approaches that have been explained by different people, I am not sure on how to apply these solutions to my case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; My attempt is based on the SUGI submission (&lt;A href="http://www2.sas.com/proceedings/sugi28/118-28.pdf)&amp;nbsp;" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/118-28.pdf)&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro renameallcols(lib,dsn);
	
	Options Pageno= 1 NoDate; 
	Proc Contents Data = &amp;amp;Lib..&amp;amp;dsn; 
	Title "Before Renaming All Variables"; 
	Run; 
	
	Proc Sql NoPrint;
		Select nvar into :num_vars
			From dictionary.tables
			Where libname="&amp;amp;LIB" 
			and memname="&amp;amp;DSN";
		Select Distinct(name) into :var1-
			:var%TRIM(%LEFT(&amp;amp;num_vars))
			From dictionary.columns
			Where libname="&amp;amp;LIB" 
			and memname="&amp;amp;DSN";
	Quit;
	Run;
	
	Proc Datasets library=&amp;amp;LIB;
		Modify &amp;amp;DSN;
		Rename
		%Do i=1 %to &amp;amp;num_vars;
			&amp;amp;&amp;amp;var&amp;amp;i=Col_&amp;amp;i.
		%End;
		;
	Quit;
	Run;
	
	Options Pageno= 1 NoDate; 
		Proc Contents Data = &amp;amp;Lib..&amp;amp;dsn; 
		Title "Before Renaming All Variables"; 
	Run; 
%Mend renameallcols;

%renameallcols(SASHelp,Air); &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I have made a minor modification to adjust to my needs i.e. the name that is being assigned is a little different that what was being discussed in the paper. In most of the relevant posts that I see in the community, a lot of people are trying to define a "rename" list where they define "oldname = newname" and save it and run it in a do-while loop. I think the approach adopted by the author of the paper is very similar. Can someone kindly explain why the above is failing ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 15:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496616#M131379</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-09-18T15:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all the column names of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496619#M131381</link>
      <description>&lt;P&gt;Are you trying to rename all the variables to&amp;nbsp;COL1-COLN?&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 15:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496619#M131381</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-18T15:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all the column names of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496622#M131385</link>
      <description>&lt;P&gt;Your issue is with the first step. The sashelp or dictionary tables are uppercase, so make sure to upper case them in the query.&lt;/P&gt;
&lt;P&gt;And you really don't want to change the SASHELP datasets so try a different test data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a simplified version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro renameallcols(lib,dsn);
		Proc Contents Data = &amp;amp;Lib..&amp;amp;dsn; 
		Title "Before Renaming All Variables"; 
	    Run; 
	
	Proc Sql NoPrint;
		Select Distinct(name) into :var1-
			From dictionary.columns
			Where libname=%upcase("&amp;amp;LIB")
			and memname=%upcase("&amp;amp;DSN");
	Quit;
    %let num_vars = &amp;amp;sqlobs.;
	
	Proc Datasets library=&amp;amp;LIB;
		Modify &amp;amp;DSN;
		Rename
		%Do i=1 %to &amp;amp;num_vars;
			&amp;amp;&amp;amp;var&amp;amp;i=Col_&amp;amp;i.
		%End;
		;
	Quit;

	 
		Proc Contents Data = &amp;amp;Lib..&amp;amp;dsn; 
		Title "After Renaming All Variables"; 
	    Run; 
%Mend renameallcols;



data work.air;
set sashelp.air;
run;
options mprint symbolgen;
%renameallcols(work,Air); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Sep 2018 16:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496622#M131385</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-18T16:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all the column names of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496623#M131386</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Failing &lt;/STRONG&gt;is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or at least clearly explain the unexpected output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that messing with the data sets in the SASHELP library may not be a good idea. And potentially in some environments they may even be read only so you can't rename the variables in place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I make a copy of SASHELP.Class in my work library then this macro did rename the variables in work.class.&lt;/P&gt;
&lt;P&gt;SASHELP.AIR does not exist in my install.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 16:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496623#M131386</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-18T16:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all the column names of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496629#M131389</link>
      <description>&lt;P&gt;It sounds like your IT people are doing their job, ensuring that you don't monk up stuff.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 16:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496629#M131389</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-18T16:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename all the column names of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496661#M131397</link>
      <description>&lt;P&gt;If you are familiar with hashes. There is away using Hashes as it accepts literal expressions. Looping num and char arrays and feeding into hash obj at run time hash.definekey(' ')&amp;nbsp; in a loop. Hash guru PD aka Paul Dorfman who is very busy now and will be here in a couple of weeks or less&amp;nbsp; has demonstrated alike in many of his papers. You could output the hash renamed contents to a dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not recommending, however it's nice to bring some awareness while I got lucky to receive&amp;nbsp;privileges from PD on a personal level&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 18:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-all-the-column-names-of-a-dataset/m-p/496661#M131397</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-18T18:13:17Z</dc:date>
    </item>
  </channel>
</rss>

