<?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 question in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564213#M11007</link>
    <description>&lt;P&gt;The macro processor ignores text inside of single quote characters.&amp;nbsp; Use double quote characters instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cats(name,'=',name,"_&amp;amp;suffix")&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Jun 2019 17:15:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-06-06T17:15:39Z</dc:date>
    <item>
      <title>Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564211#M11006</link>
      <description>&lt;P&gt;I am trying to add a&amp;nbsp;suffix to all variables, but below codes give me an error message. The message says,&amp;nbsp;&lt;/P&gt;&lt;P&gt;"NOTE 137-205: Line generated by the invoked macro "SUFFIXTOALLVAR".&lt;BR /&gt;2 quit; data &amp;amp;ndsn;set &amp;amp;lib..&amp;amp;dsn (rename=(&amp;amp;list)); run;&lt;BR /&gt;-&lt;BR /&gt;23&lt;BR /&gt;ERROR 23-7: Invalid value for the RENAME option."&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I am not much familiar with SQL, so I would really appreciate it if anybody can help.&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;%macro suffixtoallvar(lib, dsn, suffix, ndsn);
	proc contents data=&amp;amp;lib..&amp;amp;dsn noprint;
	run;
	proc sql noprint;
		select cats(name,'=',name,'_&amp;amp;suffix')
		into :list
		separated by ' '
		from dictionary.columns
			where libname='WORK' and memname='&amp;amp;ndsn';
	quit;
	data &amp;amp;ndsn;set &amp;amp;lib..&amp;amp;dsn (rename=(&amp;amp;list));
	run;
%mend suffixtoallvar;

%suffixtoallvar(MM18, RES_WK_MUSICEVENT, me, res_wk_me);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 17:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564211#M11006</guid>
      <dc:creator>brainupgraded</dc:creator>
      <dc:date>2019-06-06T17:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564213#M11007</link>
      <description>&lt;P&gt;The macro processor ignores text inside of single quote characters.&amp;nbsp; Use double quote characters instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cats(name,'=',name,"_&amp;amp;suffix")&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jun 2019 17:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564213#M11007</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-06T17:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564215#M11008</link>
      <description>&lt;P&gt;Thanks! But I still get the same error message. It seems that it's about the rename statement in the last datastep: "&amp;amp;dsn (rename=(&amp;amp;list));" "&amp;amp;" before list seems to be the problem according to SAS log. Any solution?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 17:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564215#M11008</guid>
      <dc:creator>brainupgraded</dc:creator>
      <dc:date>2019-06-06T17:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564226#M11010</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145941"&gt;@brainupgraded&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks! But I still get the same error message. It seems that it's about the rename statement in the last datastep: "&amp;amp;dsn (rename=(&amp;amp;list));" "&amp;amp;" before list seems to be the problem according to SAS log. Any solution?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It would only be generating an error complaining about &amp;amp;LIST if the macro variable LIST did not get defined.&lt;/P&gt;
&lt;P&gt;That could happen with your query since the INTO clause of a SELECT statement will NOT create the macro variable if the query doesn't find any matching records.&lt;/P&gt;
&lt;P&gt;The fix for that is to set a value for list BEFORE the query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that your query should always not find any matching records.&amp;nbsp; You probably do not have any datasets named '&amp;amp;ndsn' since &amp;amp; is not normally a valid character to use in a dataset name.&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;Make sure to use double quotes when want the macro processor to resolve text inside of quotes.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 18:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564226#M11010</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-06T18:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564242#M11011</link>
      <description>&lt;P&gt;Why are you running PROC CONTENTS without either printing the result or using the OUT= option to make a dataset?&lt;/P&gt;
&lt;P&gt;Why are you (once you fix the quotes) asking for variable names from the TARGET dataset instead of the SOURCE dataset?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 18:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564242#M11011</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-06T18:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564245#M11012</link>
      <description>&lt;P&gt;I am trying to write a macro for this:&amp;nbsp;&lt;A href="http://support.sas.com/kb/48/674.html" target="_blank"&gt;http://support.sas.com/kb/48/674.html.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I am doing it because I have multiple datasets I want to run with this renaming macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only reason I run Proc Contents with noprint option is that somebody suggested it on another webpage. Does it affect dictionary.columns perhaps?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just found a macro called "ren_stem" and it works great. But I just want to understand which parts I am wrong about in my codes.&lt;/P&gt;&lt;P&gt;I tried your suggestion about "%let list=" but I am not sure what to put on the right side of the equal sign. I would really appreciate it if you can correct my codes.&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>Thu, 06 Jun 2019 18:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564245#M11012</guid>
      <dc:creator>brainupgraded</dc:creator>
      <dc:date>2019-06-06T18:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564248#M11013</link>
      <description>&lt;P&gt;Before you can create a macro get the code working first.&lt;/P&gt;
&lt;P&gt;You can use EITHER proc contents OR dictionary.columns. No need to use both.&lt;/P&gt;
&lt;P&gt;PROC CONTENTS is much easier to understand and debug.&amp;nbsp; Plus if you have a lot of open librefs it can be a lot faster.&lt;/P&gt;
&lt;P&gt;So first get this to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=mm18.res_wk_musicevent noprint out=_contents;
run;

proc sql noprint;
%let list=;
select cats(name,'=',name,'_me')
  into :list separated by ' '
  from _contents 
;
quit;

data res_wk_me;
  set mm18.res_wk_musicevent;
  rename &amp;amp;list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that works then start replacing the variable parts with macro variable references. Watch out when using string literals that you use appropriate outer quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let in=mm18.res_wk_musicevent;
%let suffix=me;
%let out=res_wk_me;

proc contents data=&amp;amp;in. noprint out=_contents;
run;

proc sql noprint;
%let list=;
select cats(name,'=',name,'_',"&amp;amp;suffix.")
  into :list separated by ' '
  from _contents 
;
quit;

data &amp;amp;out.;
  set &amp;amp;in.;
  rename &amp;amp;list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See if that works.&lt;/P&gt;
&lt;P&gt;Then convert it into a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rename(in,suffix,out);
proc contents data=&amp;amp;in. noprint out=_contents;
run;

proc sql noprint;
%let list=;
select cats(name,'=',name,'_',"&amp;amp;suffix.")
  into :list separated by ' '
  from _contents 
;
quit;

data &amp;amp;out.;
  set &amp;amp;in.;
  rename &amp;amp;list;
run;
%mend rename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And try calling the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rename(in=mm18.res_wk_musicevent,suffix=me,out=res_wk_me);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 18:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564248#M11013</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-06T18:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564252#M11014</link>
      <description>Everything works perfectly. Thank you so much for your help! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 06 Jun 2019 18:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564252#M11014</guid>
      <dc:creator>brainupgraded</dc:creator>
      <dc:date>2019-06-06T18:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564294#M11022</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145941"&gt;@brainupgraded&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to add a&amp;nbsp;suffix to all variables, but below codes give me an error message. The message says,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"NOTE 137-205: Line generated by the invoked macro "SUFFIXTOALLVAR".&lt;BR /&gt;2 quit; data &amp;amp;ndsn;set &amp;amp;lib..&amp;amp;dsn (rename=(&amp;amp;list)); run;&lt;BR /&gt;-&lt;BR /&gt;23&lt;BR /&gt;ERROR 23-7: Invalid value for the RENAME option."&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I am not much familiar with SQL, so I would really appreciate it if anybody can help.&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;%macro suffixtoallvar(lib, dsn, suffix, ndsn);
	proc contents data=&amp;amp;lib..&amp;amp;dsn noprint;
	run;
	proc sql noprint;
		select cats(name,'=',name,'_&amp;amp;suffix')
		into :list
		separated by ' '
		from dictionary.columns
			where libname='WORK' and memname=&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;'&amp;amp;ndsn'&lt;/FONT&gt;&lt;/STRONG&gt;;
	quit;
	data &amp;amp;ndsn;set &amp;amp;lib..&amp;amp;dsn (rename=(&amp;amp;list));
	run;
%mend suffixtoallvar;

%suffixtoallvar(MM18, RES_WK_MUSICEVENT, me, &lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;res_wk_me&lt;/FONT&gt;&lt;/STRONG&gt;);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In addition to the macro variable and quotes issue, the DICTIONARY tables will want the MEMNAME to also be all capitals as you show WORK since that is how the data set names are stored. So "res_wk_me" would not be in the dictionary table so the list would be empty because a matching member name wasn't found.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 20:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-question/m-p/564294#M11022</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-06T20:27:09Z</dc:date>
    </item>
  </channel>
</rss>

