<?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: proc sql, renaming all but a few variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395691#M95478</link>
    <description>Thanks! I'll give that a try.</description>
    <pubDate>Wed, 13 Sep 2017 18:20:57 GMT</pubDate>
    <dc:creator>MillerEL</dc:creator>
    <dc:date>2017-09-13T18:20:57Z</dc:date>
    <item>
      <title>proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395674#M95473</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with ~200 variables. I need to rename the entire dataset with the exception of 10 variables. Previous analysts typed out each of the 190 variables, but I'm trying to streamline the code. The following is what I came up with, and works perfectly....except it renames all the variables. Can someone help me figure out how to remove just the 10 that shouldn't be renamed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA dnld15;  
set dnld.2015;
run;

proc sql noprint;
	select cats(name,'=',name,'Z')
	into :suffixlist
	separated by ' '
	from dictionary.columns
	where libname = 'WORK' and memname = 'DNLD15' ;
	quit;

		proc datasets lib=WORK nolist nodetails;
		modify dnld15;
		rename 
		&amp;amp;suffixlist;
		run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 17:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395674#M95473</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-13T17:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395678#M95475</link>
      <description>&lt;P&gt;You could add another filter to your code:&lt;/P&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;libname&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'WORK'&lt;/SPAN&gt; and memname &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'DNLD15'&lt;/SPAN&gt; and name &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;list&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;DATA&lt;/SPAN&gt; dnld15&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;  
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; dnld&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2015&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt; noprint&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'='&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Z'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; :suffixlist
	separated &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;' '&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; dictionary&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;columns&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;libname&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'WORK'&lt;/SPAN&gt; and memname &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'DNLD15' and &lt;STRONG&gt;name not in (list)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;
	&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

		&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;datasets&lt;/SPAN&gt; lib&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;WORK nolist nodetails&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
		modify dnld15&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
		&lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt; 
		&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;suffixlist&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
		&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395678#M95475</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-13T18:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395683#M95476</link>
      <description>&lt;P&gt;You can get the column name from dictionary.columns too - I can't check the exact field name at the moment but add something like "and colname not in (''ABC", 'DEF')" to your where clause to exclude the listed columns and asuming colname is the field name in dictionary.columns which holds that info.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395683#M95476</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-13T18:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395691#M95478</link>
      <description>Thanks! I'll give that a try.</description>
      <pubDate>Wed, 13 Sep 2017 18:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395691#M95478</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-13T18:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395694#M95479</link>
      <description>&lt;P&gt;Yes sorry, i should have mentioned what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt;&amp;nbsp;in the change i made to your code but i was lazy. If you noticed my addition to your where condition, the name column is the column that has a list of variables names in the dictionary.columns metadata. So you can basically filter with IN operator.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395694#M95479</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-13T18:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395698#M95480</link>
      <description>Thanks. I tried this but my syntax was a little different. This worked great!</description>
      <pubDate>Wed, 13 Sep 2017 18:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395698#M95480</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-13T18:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395702#M95481</link>
      <description>&lt;P&gt;Well, darn. It did rename all but 10 of the variables...but it left those un-renamed variables out of the dataset. How do I keep them in?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395702#M95481</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-13T18:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395706#M95483</link>
      <description>&lt;P&gt;Are you dropping somewhere? Can you share your code plz&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395706#M95483</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-13T18:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395708#M95484</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99818"&gt;@MillerEL&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Well, darn. It did rename all but 10 of the variables...but it left those un-renamed variables out of the dataset. How do I keep them in?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is nothing in the proposed solutions that would drop any variables.&lt;/P&gt;
&lt;P&gt;Show what you did that dropped those variables?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395708#M95484</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-13T18:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395709#M95485</link>
      <description>The code I posted above is it. When I run a proc contents on dnld15, it is only showing the renamed variables. This file feeds into a second program, but the second program is about 2000 lines long...and there isn't a single drop statement in either program.</description>
      <pubDate>Wed, 13 Sep 2017 18:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395709#M95485</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-13T18:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395718#M95487</link>
      <description>I found it. Syntax error - forgot to check my log. The file didn't finish correctly and the proc contents was on an old file. Sorry! and Thank you!</description>
      <pubDate>Wed, 13 Sep 2017 18:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395718#M95487</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-13T18:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395720#M95488</link>
      <description>&lt;P&gt;check the case, ie upper, lower, mixed for variable names or data set name.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395720#M95488</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-13T18:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, renaming all but a few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395723#M95489</link>
      <description>Syntax error - forgot to check my log. The file didn't finish correctly and the proc contents was on an old file. Sorry! and Thank you!</description>
      <pubDate>Wed, 13 Sep 2017 18:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-renaming-all-but-a-few-variables/m-p/395723#M95489</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-13T18:51:48Z</dc:date>
    </item>
  </channel>
</rss>

