<?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: Macro error for indata, if then statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627340#M185171</link>
    <description>&lt;P&gt;You asked SAS macro processor to use this code to generate an SQL SELECT statement where the dataset name comes from a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select count(*) into:tot from &amp;amp;indata.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You then called the macro with the value of INDATA set to **NOTHING**. So it generated this statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select count(*) into:tot from ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the error is saying SAS needs to see something there after FROM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To fix this just remove the extra line from the end of your source code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%grp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2020 21:48:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-25T21:48:42Z</dc:date>
    <item>
      <title>Macro error for indata, if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627248#M185104</link>
      <description>&lt;P&gt;I would like to group small levels for a list of categorical variable using macro in SAS EG7.15, but it does not work. the same step worked before. I wonder whether others encountered the same issue. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &amp;amp;indata. cannot be invoked by SAS even I give a value. Here is error. if I replace the &amp;amp;indata with the true name. no following errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: GROUP, ORDER.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error under group_level_&amp;amp;var.&lt;/P&gt;&lt;P&gt;____________________&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE,&lt;BR /&gt;GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.&lt;/P&gt;&lt;P&gt;160: LINE and COLUMN cannot be determined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;error under if then in the data step:&lt;/P&gt;&lt;P&gt;ERROR 160-185: No matching IF-THEN clause.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;Here is the code:&lt;/P&gt;&lt;P&gt;%macro grp(indata=, outdata=, threshold=);&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(*) into:tot from &amp;amp;indata.; quit;&lt;/P&gt;&lt;P&gt;/* Count the number of values in the string */&lt;BR /&gt;%let count=%sysfunc(countw(&amp;amp;var_list.));&lt;BR /&gt;/* Loop through the total number of values */&lt;BR /&gt;%do i = 1 %to &amp;amp;count;&lt;BR /&gt;%let var=%qscan(&amp;amp;var_list,&amp;amp;i,%str( ));&lt;BR /&gt;%put &amp;amp;var.;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table %unquote(frq_&amp;amp;VAR.) as&lt;BR /&gt;select "&amp;amp;var." as var format=$30., &amp;amp;var. as %unquote(level_&amp;amp;VAR.) format=$30., count(*) as N&lt;BR /&gt;, calculated n/&amp;amp;tot. as Percent format=percent7.0&lt;BR /&gt;from &amp;amp;indata.&lt;BR /&gt;group by 1,2&lt;BR /&gt;order by 1,2 desc; quit;&lt;/P&gt;&lt;P&gt;data %unquote(fgrp_&amp;amp;VAR.2); set %unquote(frq_&amp;amp;VAR.); if n&amp;lt;&amp;amp;threshold. then %unquote(grp_level_&amp;amp;VAR.) = 'Other';&lt;BR /&gt;else %unquote(grp_level_&amp;amp;VAR.) = %unquote(level_&amp;amp;VAR.);run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%grp(indata=lib.abc(where=(TVH2 NE ''))), outdata=lib.out, threshold=800);&lt;BR /&gt;%grp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627248#M185104</guid>
      <dc:creator>grace999</dc:creator>
      <dc:date>2020-02-25T17:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error for indata, if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627250#M185106</link>
      <description>&lt;P&gt;Turn on the MPRINT option.&amp;nbsp; Copy the text from the SAS log. Make sure to include the statements that the error is complaining about.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When pasting the lines into your post make sure to use the Insert Code button on the editor.&amp;nbsp; Otherwise this forum will treat it as paragraphs to be reflowed and we will lose the connection between the error message and the line of code it is complaining about.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:21:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627250#M185106</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-25T17:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error for indata, if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627254#M185110</link>
      <description>&lt;P&gt;It is hard to read the code the way you posted it. But let's take a stab at it.&lt;/P&gt;
&lt;P&gt;Your macro is referencing macro variables that are not inputs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears to be using the value of VAR_LIST.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is also changing the values of macro variables TOT, COUNT, I, VAR without defining them as LOCAL.&lt;/P&gt;
&lt;P&gt;You are calling the macro twice. Once with values for the inputs, and then again without.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Is the issue the second call to the macro?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627254#M185110</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-25T17:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error for indata, if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627328#M185162</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; Here is the code:

%macro grp(indata=, outdata=, threshold=);
proc sql;
select count(*) into:tot from &amp;amp;indata.; quit;

/* Count the number of values in the string */
%let count=%sysfunc(countw(&amp;amp;var_list.));
/* Loop through the total number of values */
%do i = 1 %to &amp;amp;count;
%let var=%qscan(&amp;amp;var_list,&amp;amp;i,%str( ));
%put &amp;amp;var.;

proc sql;
create table %unquote(frq_&amp;amp;VAR.) as
select "&amp;amp;var." as var format=$30., &amp;amp;var. as %unquote(level_&amp;amp;VAR.) format=$30., count(*) as N
, calculated n/&amp;amp;tot. as Percent format=percent7.0
from &amp;amp;indata.
group by 1,2
order by 1,2 desc; quit;

data %unquote(fgrp_&amp;amp;VAR.2); set %unquote(frq_&amp;amp;VAR.); if n&amp;lt;&amp;amp;threshold. then %unquote(grp_level_&amp;amp;VAR.) = 'Other';
else %unquote(grp_level_&amp;amp;VAR.) = %unquote(level_&amp;amp;VAR.);run;
%end;
%mend;
%grp(indata=lib.abc(where=(TVH2 NE ''))), outdata=lib.out, threshold=800);
%grp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "GRP".&lt;BR /&gt;66 select count(*) into:tot from &amp;amp;indata.;&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.&lt;/P&gt;&lt;P&gt;65 ! %unquote(grp_level_&amp;amp;VAR.) = 'Other'; else if n&amp;gt;=&amp;amp;threshold. then %unquote(grp_level_&amp;amp;VAR.) = %unquote(level_&amp;amp;VAR.);run;&lt;BR /&gt;____&lt;BR /&gt;160&lt;BR /&gt;ERROR 160-185: No matching IF-THEN clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro function "UNQUOTE".&lt;BR /&gt;65 grp_level_Var&lt;BR /&gt;____________________&lt;BR /&gt;22&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE,&lt;BR /&gt;GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 21:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627328#M185162</guid>
      <dc:creator>grace999</dc:creator>
      <dc:date>2020-02-25T21:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error for indata, if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627340#M185171</link>
      <description>&lt;P&gt;You asked SAS macro processor to use this code to generate an SQL SELECT statement where the dataset name comes from a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select count(*) into:tot from &amp;amp;indata.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You then called the macro with the value of INDATA set to **NOTHING**. So it generated this statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select count(*) into:tot from ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the error is saying SAS needs to see something there after FROM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To fix this just remove the extra line from the end of your source code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%grp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 21:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627340#M185171</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-25T21:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error for indata, if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627348#M185176</link>
      <description>&lt;P&gt;A couple of issues are helping to hide the problem.&amp;nbsp; Clear these up first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%grp(indata=lib.abc(where=(TVH2 NE ''))), outdata=lib.out, threshold=800);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There is an extra right-hand parenthesis.&amp;nbsp; Change ))) to ))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There is absolutely no reason that I can see to use %qscan.&amp;nbsp; Use %scan instead, and you can get rid of all the %unquote functions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;These might or might not solve the problems, but it will make the results a little clearer.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 22:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627348#M185176</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-25T22:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error for indata, if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627523#M185274</link>
      <description>Thanks to both Tom and Astounding!</description>
      <pubDate>Wed, 26 Feb 2020 14:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error-for-indata-if-then-statement/m-p/627523#M185274</guid>
      <dc:creator>grace999</dc:creator>
      <dc:date>2020-02-26T14:58:40Z</dc:date>
    </item>
  </channel>
</rss>

