<?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 variables automatically before merge datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262491#M51263</link>
    <description>&lt;P&gt;One issue, the memname should be uppercase. Otherwise you won't get a match in the dictionary table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This call to the macro at least is using mixed case.&lt;/P&gt;
&lt;P&gt;%RENAME (dataset1= LeafL, dataset2= LeafW); RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so either pass the parameter in upper case, %upcase the values at the top of the macro or use memname=upcase("&amp;amp;dataset1") in the SQL.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Apr 2016 15:42:30 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-04-08T15:42:30Z</dc:date>
    <item>
      <title>rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262391#M51210</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made the following macro but I am getting a error message in the end, someone could help me to know what I'm doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO RENAME (dataset1=, dataset2=);&lt;BR /&gt;PROC SQL;&lt;BR /&gt;DESCRIBE TABLE LeafL LeafW dictionary.columns;&lt;BR /&gt;QUIT;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;SELECT libname, memname, name&lt;BR /&gt;FROM dictionary.columns&lt;BR /&gt;WHERE libname= "WORK" and memname= "&amp;amp;dataset1";&lt;BR /&gt;QUIT;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;SELECT libname, memname, name&lt;BR /&gt;FROM dictionary.columns&lt;BR /&gt;WHERE libname= "WORK" and memname= "&amp;amp;dataset2";&lt;BR /&gt;QUIT;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;SELECT trim(name) || "=" || "&amp;amp;dataset2" || "_" || name&lt;BR /&gt;INTO :renamevar separated by " "&lt;BR /&gt;FROM&lt;BR /&gt;(&lt;BR /&gt;SELECT name&lt;BR /&gt;FROM dictionary.columns&lt;BR /&gt;WHERE libname= "WORK" and memname= "&amp;amp;dataset2" and upcase(name) in&lt;BR /&gt;(&lt;BR /&gt;SELECT upcase(name)&lt;BR /&gt;FROM dictionary.columns&lt;BR /&gt;WHERE libname= "WORK" and memname= "&amp;amp;dataset1" and upcase(name) ne "PLOT"&lt;BR /&gt;)&lt;BR /&gt;);&lt;BR /&gt;QUIT&lt;BR /&gt;%PUT &amp;amp;renamevar;&lt;BR /&gt;DATA Land;&lt;BR /&gt;MERGE LeafL LeafW(rename=(&amp;amp;renamevar));&lt;BR /&gt;BY plot;&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND;&lt;/P&gt;&lt;P&gt;%RENAME (dataset1= LeafL, dataset2= LeafW); RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the log windows (below) seem like there is something wrong with the macro variable but I don't know exactly what happen.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference RENAMEVAR not resolved.&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "RENAME".&lt;BR /&gt;7 BY plot;&lt;BR /&gt;--&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 12:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262391#M51210</guid>
      <dc:creator>Fersal</dc:creator>
      <dc:date>2016-04-08T12:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262394#M51211</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sql query which creates the macro variable &lt;STRONG&gt;renamevar&lt;/STRONG&gt; returns no rows thus the message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider the following example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select age into :age from sashelp.class where age=678;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;age;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 12:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262394#M51211</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-04-08T12:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262403#M51215</link>
      <description>&lt;P&gt;To b e honest, I am quite suprised that a question like this comes up enough to warrant a macro for it? &amp;nbsp;I mean you must know what data you have coming in what data goes where etc. &amp;nbsp;In most case a small change to the structure of the data will eradicate the need for merging same data back to same data. &amp;nbsp;Could you give an exampe of where this would be needed?&lt;/P&gt;
&lt;P&gt;As for the code, well you could do something like the below, but then you need to put in checks to see if there are any rows which have the same name element, data types etc. &amp;nbsp;It just seems like a large process with nothing to gain from it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data tmp;&lt;BR /&gt; set sashelp.class (rename=(age=temp));&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt; select cats(NAME,"=_",NAME)&lt;BR /&gt; into :VLIST separated by " "&lt;BR /&gt; from DICTIONARY.COLUMNS &lt;BR /&gt; where LIBNAME="WORK" &lt;BR /&gt; and MEMNAME="TMP"&lt;BR /&gt; and upcase(NAME) ne "NAME"&lt;BR /&gt; and NAME in (select NAME from DICTIONARY.COLUMNS where LIBNAME="SASHELP" and MEMNAME="CLASS");&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt; merge sashelp.class tmp (rename=(&amp;amp;VLIST.));&lt;BR /&gt; by name;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 12:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262403#M51215</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-08T12:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262424#M51218</link>
      <description>&lt;P&gt;When you use the INTO clause on a SELECT statement to create a macro variable the variable is not created when there are no rows returned by the SELECT statement. &amp;nbsp;You just need to set the value BEFORE the select statement to prevent the error you are seeing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
%let renamevar=;
  SELECT trim(name) || "=" || "&amp;amp;dataset2" || "_" || name
    INTO :renamevar separated by " "
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2016 13:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262424#M51218</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-04-08T13:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262480#M51254</link>
      <description>&lt;P&gt;but it works when it is out of the macro which I don't understand why...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;What I did is add WHERE upcase(name) ne "PLOT" after the last query, now it works but I still get the following warning message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: This SAS global statement is not supported in PROC SQL. It has been ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 15:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262480#M51254</guid>
      <dc:creator>Fersal</dc:creator>
      <dc:date>2016-04-08T15:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262481#M51255</link>
      <description>&lt;P&gt;Thanks for your comment, the reason I want to use a macro is because I have a lot of data set which I want to merge and the name of the most variables are the same but can be different values in each of them.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 15:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262481#M51255</guid>
      <dc:creator>Fersal</dc:creator>
      <dc:date>2016-04-08T15:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262491#M51263</link>
      <description>&lt;P&gt;One issue, the memname should be uppercase. Otherwise you won't get a match in the dictionary table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This call to the macro at least is using mixed case.&lt;/P&gt;
&lt;P&gt;%RENAME (dataset1= LeafL, dataset2= LeafW); RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so either pass the parameter in upper case, %upcase the values at the top of the macro or use memname=upcase("&amp;amp;dataset1") in the SQL.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 15:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262491#M51263</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-08T15:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262535#M51280</link>
      <description>&lt;P&gt;Hi, I also have tried this, but it doesn't work&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 17:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262535#M51280</guid>
      <dc:creator>Fersal</dc:creator>
      <dc:date>2016-04-08T17:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: rename variables automatically before merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262846#M51401</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, but my question is, what are these different variables, where do they come from, why do you not know what they are upfront? &amp;nbsp;It sounds like the process has broken further up the chain and now your trying to patch it together again.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 09:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-variables-automatically-before-merge-datasets/m-p/262846#M51401</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-11T09:24:56Z</dc:date>
    </item>
  </channel>
</rss>

