<?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 works when written out but not in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972610#M377537</link>
    <description>FreelanceReinh ，&lt;BR /&gt;Good Point. Learned it happy.</description>
    <pubDate>Thu, 14 Aug 2025 09:31:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2025-08-14T09:31:05Z</dc:date>
    <item>
      <title>PROC SQL works when written out but not in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972599#M377531</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;
&lt;P&gt;I have a (what I think to be) simple macro statement. I am trying to grab formats for some variables. The variable names are irrelevant, so I am not providing a dataset. Any dataset with two or three variables will do. Note that varlist is a space separated list of variable names in the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MakeSummary(lib=WORK, dset=, varlist=, outfmt=SummaryFmt);

%LET MultRespVariablesList=%str(%')%sysfunc(tranwrd(%upcase(&amp;amp;varlist.),%str( ),%str(',')))%str(%');
%PUT &amp;amp;=MultRespVariablesList;
proc sql noprint;
        create table _varfmt as
        select name, format as fmtname
        from dictionary.columns
        where upcase(libname) eq upcase("&amp;amp;lib")
          and upcase(memname) eq upcase("&amp;amp;dset")
          and upcase(name) IN (&amp;amp;MultRespVariablesList.);  
    quit;
%mend;
%MakeSummary(lib=WORK, dset=test, varlist=Var1 Var2 Var3, outfmt=SummaryFmt);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives me:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string,
              a numeric constant, a datetime constant, a missing value, (, -, SELECT.

ERROR 76-322: Syntax error, statement will be ignored.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, if I turn on&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And copy and past the output from the log, I get:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table _varfmt as select name, format as fmtname from
dictionary.columns where upcase(libname) eq upcase("WORK") and upcase(memname) eq
upcase("test") and upcase(name) IN
('VAR1','VAR2','VAR3');
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And that runs fine.&lt;/P&gt;
&lt;P&gt;I am getting the annoying:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space between a quoted string and the succeeding identifier is recommended.

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I'm not certain that it relates here.&lt;/P&gt;
&lt;P&gt;Why does the output of MPRINT, which should be what the macro processor is generating, working, but when I run the macro, it doesn't work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2025 06:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972599#M377531</guid>
      <dc:creator>JacquesR</dc:creator>
      <dc:date>2025-08-14T06:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL works when written out but not in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972600#M377532</link>
      <description>&lt;P&gt;Try to use FINDW() instead of making a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
input id var1-var3;
format var3 f4.2;
cards;
1 1 2 3
;

%macro MakeSummary(lib=WORK, dset=, varlist=, outfmt=SummaryFmt);

proc sql noprint;
        create table _varfmt as
        select name, format as fmtname
        from dictionary.columns
        where upcase(libname) eq "%upcase(&amp;amp;lib)"
          and upcase(memname) eq "%upcase(&amp;amp;dset)"
          and findw("%upcase(&amp;amp;varlist.)", upcase(strip(name))) ;  
    quit;
%mend;
%MakeSummary(lib=WORK, dset=test, varlist=Var1 Var2 Var3, outfmt=SummaryFmt);&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Aug 2025 06:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972600#M377532</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-08-14T06:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL works when written out but not in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972605#M377533</link>
      <description>&lt;P&gt;I'm still curious about why the MPRINT code works, but the macro doesn't?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2025 07:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972605#M377533</guid>
      <dc:creator>JacquesR</dc:creator>
      <dc:date>2025-08-14T07:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL works when written out but not in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972607#M377535</link>
      <description>&lt;P&gt;If you really need to make your code worked, just add %UNQUOTE into it to get rid of delta character generated by %str().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
input id var1-var3;
format var3 f4.2;
cards;
1 1 2 3
;

%macro MakeSummary(lib=WORK, dset=, varlist=, outfmt=SummaryFmt);

%LET MultRespVariablesList=%str(%')%sysfunc(tranwrd(%upcase(&amp;amp;varlist.),%str( ),%str(',')))%str(%');
%PUT &amp;amp;=MultRespVariablesList;
proc sql noprint;
        create table _varfmt as
        select name, format as fmtname
        from dictionary.columns
        where upcase(libname) eq upcase("&amp;amp;lib")
          and upcase(memname) eq upcase("&amp;amp;dset")
          and upcase(name) IN (&lt;STRONG&gt;%unquote(&lt;/STRONG&gt;&amp;amp;MultRespVariablesList.));  
    quit;
%mend;
%MakeSummary(lib=WORK, dset=test, varlist=Var1 Var2 Var3, outfmt=SummaryFmt);&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Aug 2025 08:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972607#M377535</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-08-14T08:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL works when written out but not in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972609#M377536</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263372"&gt;@JacquesR&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If you really need to make your code worked, just add %UNQUOTE into it to get rid of delta character generated by %str().&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;... &lt;EM&gt;and&lt;/EM&gt; use the %QSYSFUNC function instead of %SYSFUNC&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#999999"&gt;%LET MultRespVariablesList=%str(%')%&lt;STRONG&gt;&lt;FONT color="#800080"&gt;q&lt;/FONT&gt;&lt;/STRONG&gt;sysfunc(tranwrd(%upcase(&amp;amp;varlist.),%str( ),%str(',')))%str(%');&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;to make the macro quoting consistent in the first place and to avoid the annoying notes in the log, especially "NOTE 49-169." Otherwise you produce a mixture of macro-quoted and unquoted single quotation marks, which can be seen in the output of a &lt;FONT face="courier new,courier"&gt;%put _user_;&lt;/FONT&gt; statement:&lt;/P&gt;
&lt;PRE&gt;MAKESUMMARY MULTRESPVARIABLESLIST &amp;#1;&amp;#17;&amp;#2;SEX','AGE','WEIGHT&amp;#1;&amp;#17;&amp;#2;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2025 08:59:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972609#M377536</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-08-14T08:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL works when written out but not in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972610#M377537</link>
      <description>FreelanceReinh ，&lt;BR /&gt;Good Point. Learned it happy.</description>
      <pubDate>Thu, 14 Aug 2025 09:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-works-when-written-out-but-not-in-macro/m-p/972610#M377537</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-08-14T09:31:05Z</dc:date>
    </item>
  </channel>
</rss>

