<?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: Using Macro with PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491262#M128784</link>
    <description>&lt;P&gt;You coded:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;application_&amp;amp;p01&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That makes SAS look for a macro variable named P01, which doesn't exist.&amp;nbsp; You have a macro variable named P.&amp;nbsp; You can add a dot after the P, to tell the macro processor that that is the end of the macro variable name.&amp;nbsp; So:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;application_&amp;amp;p.01&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should fix the macro resolution error.&amp;nbsp; SAS will resolve macro variable P, and the 01 is just text.&amp;nbsp; But big picture, there may be better ways to do this, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;suggested.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Aug 2018 14:29:37 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2018-08-30T14:29:37Z</dc:date>
    <item>
      <title>Using Macro with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491239#M128773</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to count the number of&amp;nbsp;DOCDB_FAMILY_ID per&amp;nbsp;psn_name per month between 1990 and 2015 by following codes,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro each_month;
%local p;
%do p=1990 %to 2015;

PROC SQL;
create table Sa_step3.number_of_application&amp;amp;p as
select
co.psn_name,
count(distinct(case when month = 1 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p01,
count(distinct(case when month = 1 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p01,
count(distinct(case when month = 2 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p02,
count(distinct(case when month = 2 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p02,
count(distinct(case when month = 3 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p03,
count(distinct(case when month = 3 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p03,
count(distinct(case when month = 4 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p04,
count(distinct(case when month = 4 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p04,
count(distinct(case when month = 5 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p05,
count(distinct(case when month = 5 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p05,
count(distinct(case when month = 6 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p06,
count(distinct(case when month = 6 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p06,
count(distinct(case when month = 7 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p07,
count(distinct(case when month = 7 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p07,
count(distinct(case when month = 8 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p08,
count(distinct(case when month = 8 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p08,
count(distinct(case when month = 9 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p09,
count(distinct(case when month = 9 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p09,
count(distinct(case when month = 10 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p10,
count(distinct(case when month = 10 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p10,
count(distinct(case when month = 11 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p11,
count(distinct(case when month = 11 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p11,
count(distinct(case when month = 12 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p12,
count(distinct(case when month = 12 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p12
from Sa_step2.year&amp;amp;p as ap
join Pat_sam.Personapplication as pe on ap.appln_id = pe.appln_id
join Pat_sam.Companies as co on pe.person_id = co.person_id
where applt_seq_nr &amp;gt; 0
and ap.ipr_type = 'PI'
group by psn_name
order by psn_name
;
quit;

%end;
   run;
 
%mend each_month;
 
%each_month&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but the result shows that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the invoked macro "EACH_MONTH".
351              create table Sa_step3.number_of_application&amp;amp;p as select co.psn_name,
351! count(distinct(case when month = 1 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p01,
                                                                                  -
                                                                                  22
                                                                                  200
351! count(distinct(case when month = 1 and granted = 1 then DOCDB_FAMILY_ID end)) as
WARNING: Apparent symbolic reference P01 not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, ',', AS, FORMAT, FROM,
              INFORMAT, INTO, LABEL, LEN, LENGTH, TRANSCODE.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Line generated by the invoked macro "EACH_MONTH".
352   granted_&amp;amp;p01, count(distinct(case when month = 2 then DOCDB_FAMILY_ID end)) as application_&amp;amp;p02,
              -
              22
              76
352!  count(distinct(case when month = 2 and granted = 1 then DOCDB_FAMILY_ID end)) as granted_&amp;amp;p02,
352! count(distinct(case when month = 3 then DOCDB_FAMILY_ID end))
WARNING: Apparent symbolic reference P01 not resolved.
WARNING: Apparent symbolic reference P02 not resolved.
WARNING: Apparent symbolic reference P02 not resolved.
WARNING: Apparent symbolic reference P03 not resolved.
WARNING: Apparent symbolic reference P03 not resolved.
WARNING: Apparent symbolic reference P04 not resolved.
WARNING: Apparent symbolic reference P04 not resolved.
WARNING: Apparent symbolic reference P05 not resolved.
WARNING: Apparent symbolic reference P05 not resolved.
WARNING: Apparent symbolic reference P06 not resolved.
WARNING: Apparent symbolic reference P06 not resolved.
WARNING: Apparent symbolic reference P07 not resolved.
WARNING: Apparent symbolic reference P07 not resolved.
WARNING: Apparent symbolic reference P08 not resolved.
WARNING: Apparent symbolic reference P08 not resolved.
WARNING: Apparent symbolic reference P09 not resolved.
WARNING: Apparent symbolic reference P09 not resolved.
WARNING: Apparent symbolic reference P10 not resolved.
WARNING: Apparent symbolic reference P10 not resolved.
WARNING: Apparent symbolic reference P11 not resolved.
WARNING: Apparent symbolic reference P11 not resolved.
WARNING: Apparent symbolic reference P12 not resolved.
WARNING: Apparent symbolic reference P12 not resolved.
ERROR 22-322: Syntax error, expecting one of the following: ;, ',', ANSIMISS, CROSS, EXCEPT, FULL,
              GROUP, HAVING, INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS, ORDER, OUTER, RIGHT,
              UNION, WHERE.

ERROR 76-322: Syntax error, statement will be ignored.&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;could you please give me any suggestion about this? beside, can i use macro variable like this ?&lt;/P&gt;&lt;P&gt;thanks in advance,&amp;nbsp;&lt;/P&gt;&lt;P&gt;best regards,&lt;/P&gt;&lt;P&gt;France&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 13:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491239#M128773</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-08-30T13:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491255#M128780</link>
      <description>&lt;P&gt;Its very hard to tell from a long line of code, and no test data/required output.&amp;nbsp; Can you not just two sqls:&lt;/P&gt;
&lt;PRE&gt;select count(docdb_family_id) as application_count
from ...
group by month;

select count(docdb_family_id) as granted_count
from ...
group by month
having granted=1;&lt;/PRE&gt;
&lt;P&gt;There isn't any need to do each month individually.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 14:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491255#M128780</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-30T14:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491262#M128784</link>
      <description>&lt;P&gt;You coded:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;application_&amp;amp;p01&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That makes SAS look for a macro variable named P01, which doesn't exist.&amp;nbsp; You have a macro variable named P.&amp;nbsp; You can add a dot after the P, to tell the macro processor that that is the end of the macro variable name.&amp;nbsp; So:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;application_&amp;amp;p.01&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should fix the macro resolution error.&amp;nbsp; SAS will resolve macro variable P, and the 01 is just text.&amp;nbsp; But big picture, there may be better ways to do this, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;suggested.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 14:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491262#M128784</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-08-30T14:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491334#M128832</link>
      <description>Dear RW9,&lt;BR /&gt;&lt;BR /&gt;thanks for your advice.&lt;BR /&gt;&lt;BR /&gt;have a nice day.&lt;BR /&gt;best regards.&lt;BR /&gt;France&lt;BR /&gt;</description>
      <pubDate>Thu, 30 Aug 2018 16:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-with-PROC-SQL/m-p/491334#M128832</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-08-30T16:27:17Z</dc:date>
    </item>
  </channel>
</rss>

