<?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 called in a data step not working (ERROR:  More positional parameters found than defined) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506442#M1324</link>
    <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transformed_class;
set sashelp.class;
newage = age * 5; /* the 5 here is a numeric literal */
newname = name !! 'X'; /* the 'X' is also a literal, in this case a string literal */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other programming languages (eg PASCAL), such things are often called "constants".&lt;/P&gt;</description>
    <pubDate>Mon, 22 Oct 2018 13:41:52 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-22T13:41:52Z</dc:date>
    <item>
      <title>Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506419#M1316</link>
      <description>&lt;P&gt;If have a data set&amp;nbsp;"branch_list_mod" - which is a column of values that I am trying to match to.&lt;/P&gt;&lt;P&gt;Then I have data set "NA_PACC_Responses" - which has a column "message_mod" that I am trying to match to the "branch_list_der".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "&lt;SPAN&gt;message_mod" is an incoming text message (so free text) that needs to be matched to a list of accepted responses.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I do this by a similarity macro, as follows:&lt;/SPAN&gt;&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 similarity (out =, text =);
	data &amp;amp;out. (keep = branch);
	set branch_list_mod;
		cost1 = min(250,spedis(strip(lowcase(branch_match)),&amp;amp;text.));
		cost2 = min(250,spedis(&amp;amp;text.,strip(lowcase(branch_match))));
		cost3 = max(cost1,cost2);
		if cost3 &amp;gt; 0 then similarity = (1 - (min(cost1,cost2)/250));
		else similarity = 1;
		if similarity &amp;gt; 0.9 then output;
	run;
%mend similarity;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But then when I call the function in a data step, it give me the error - more positional parameters found than defined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is how I call the function:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NA_PACC_Responses_der;
set NA_PACC_Responses (obs = 1);

	branch_der = %similarity(test1, message_mod);

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is an extract of the list of&amp;nbsp;accepted&amp;nbsp;responses (data set -&amp;nbsp;branch_list_der):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;oshikango&lt;BR /&gt;oshakati&lt;BR /&gt;rundu&lt;BR /&gt;ondangwa&lt;BR /&gt;opuwo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is an extract of the list of free text than can be received:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;tsumeb&lt;BR /&gt;walvis bay&lt;BR /&gt;walvis bay&lt;BR /&gt;windhoek john meinert&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;QUESTION:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What am I doing wrong in the macro writing or calling that it gives the error mentioned?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 12:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506419#M1316</guid>
      <dc:creator>BayleyVos</dc:creator>
      <dc:date>2018-10-22T12:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506421#M1317</link>
      <description>&lt;P&gt;Two mistakes here:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;(the small one) definition of the macro with named parameters, but calling it with positional parameters; use text= and out= in the macro call, or omit the equal signs in the macro definition, so the macro is defined with positional parameters only.&lt;/LI&gt;
&lt;LI&gt;(the big one) what happens when the macro is resolved&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The code after resolving the macro would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NA_PACC_Responses_der;
set NA_PACC_Responses (obs = 1);

	branch_der = data test1 (keep = branch);
	set branch_list_mod;
		cost1 = min(250,spedis(strip(lowcase(branch_match)),message_mod));
		cost2 = min(250,spedis(message_mod,strip(lowcase(branch_match))));
		cost3 = max(cost1,cost2);
		if cost3 &amp;gt; 0 then similarity = (1 - (min(cost1,cost2)/250));
		else similarity = 1;
		if similarity &amp;gt; 0.9 then output;
	run;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and end up being one big syntax ERROR.&lt;/P&gt;
&lt;P&gt;Keep in mind that the macro preprocessor is just a sophisticated text replacement system.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 12:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506421#M1317</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-22T12:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506422#M1318</link>
      <description>&lt;P&gt;When you create a macro, and then run it, as you have done, the macro substitutes text into the SAS code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A trivial example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn = dataset1;
proc means data = &amp;amp;dsn;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when run results in the following code being executed (note the text substitution)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn = dataset1;
proc means data = dataset1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And when this text substitution happens, &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;it must result in valid SAS code&lt;/STRONG&gt;&lt;/FONT&gt;. If the SAS code produced by this text substitution is not valid SAS code and produces an error, then your code won't run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, when you try to run the macro %similarity inside of a data step, the result, after text substitution looks partially like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NA_PACC_Responses_der;
    set NA_PACC_Responses (obs = 1);
    branch_der = /* the text substitution is here: */ data test1; ... run;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You cannot have a data step within a data step. That is not valid SAS code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So you need to figure out a way to do all of these calculations in a single data step; or a way to do all of these calculations in sequential data steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a possible way to do this in a single data step, please look at the LINK command. &lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n132s7tapddkc8n1my90ekgo4v0q.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n132s7tapddkc8n1my90ekgo4v0q.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506422#M1318</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-22T13:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506424#M1320</link>
      <description>&lt;P&gt;Thank you very much for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can also see why I'm getting the error - because of your excellent explanation.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BUT, I don't know how to fix it - the second error you explained.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you possibly suggest a fix for the second error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would greatly appreciate it.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506424#M1320</guid>
      <dc:creator>BayleyVos</dc:creator>
      <dc:date>2018-10-22T13:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506427#M1321</link>
      <description>&lt;P&gt;Start with working Base SAS code (step one in macro development 101):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NA_PACC_Responses_der;
set NA_PACC_Responses (obs = 1);

	branch_der = /* insert the working BASE SAS(!) code for the calculation of branch_der from data in the first observation of NA_PACC_Responses here */;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do not use any macro statements here, not even macro variables. Just do what it takes to calculate branch_der, and keep in mind that all data you want to use for this has to somehow be present in the data step; it's either in the input dataset, or you will use literals in the code.&lt;/P&gt;
&lt;P&gt;Once you have that working, you can start on identifying code parts that need to be made dynamic, and that's where the macro programming should start.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506427#M1321</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-22T13:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506440#M1322</link>
      <description>&lt;P&gt;The advice given by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is so important that I want to repeat it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, get SAS code that works in one specific instance of your problem, and only when you have that working should you think about writing the macro to work in the general case.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506440#M1322</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-22T13:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506441#M1323</link>
      <description>&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "literals in the code" you speak of - how is that done?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506441#M1323</guid>
      <dc:creator>BayleyVos</dc:creator>
      <dc:date>2018-10-22T13:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro called in a data step not working (ERROR:  More positional parameters found than defined)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506442#M1324</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transformed_class;
set sashelp.class;
newage = age * 5; /* the 5 here is a numeric literal */
newname = name !! 'X'; /* the 'X' is also a literal, in this case a string literal */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other programming languages (eg PASCAL), such things are often called "constants".&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:41:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-called-in-a-data-step-not-working-ERROR-More-positional/m-p/506442#M1324</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-22T13:41:52Z</dc:date>
    </item>
  </channel>
</rss>

