<?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: Pass a parameter in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336062#M272411</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Pass a parameter in macro

When this is resolved Internet/Catalog Customers
your program tries to do a division,

I almost always double quote my macro comparison arguments.


HAVE
====

Up to 40 obs WORK.CUSTOMER total obs=5

Obs     NAME      SEX    CUSTOMER_GROUP

 1     Alfred      M     Store Customers
 2     Alice       F     Store Customers
 3     Barbara     F     Internet/Catalog Customers
 4     Carol       F     Store Customers
 5     Henry       M     Store Customers


WANT
====

the least abudant group is INTERNET/CATALOG CUSTOMERS

Obs     NAME      SEX    AGE          CUSTOMER_GROUP

 3     Barbara     F      13    Internet/Catalog Customers

BUT I GET THE ERRO


MPRINT(TEST):   where customer_group="Internet/Catalog Customers";
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
       is required. The condition was: &amp;amp;param=A members

WITH THIS CODE
==============

%macro test(param);
    proc print data=customer;
    where customer_group="&amp;amp;param";
    %if &amp;amp;param=A members %then %do;
        title "the most abudant  group is %upcase(&amp;amp;param)";
    %end;
    %else %do;
        title "the least abudant group is %upcase(&amp;amp;param)";
    %end;
    var name gender age customer_group;

run;
%mend test;
options mprint mlogic;
%let least=Internet/Catalog Customers;
%test(&amp;amp;least);


WORKING CODE
============

Change

   %if &amp;amp;param =A members %then %do;

to

  %if "&amp;amp;param" ="A members" %then %do;

Also she need a run;quit;

FULL SOLUTION
=============

data customer( keep=name sex age customer_group);
  set sashelp.class(obs=5);
  if name='Barbara' then customer_group ='Internet/Catalog Customers';
  else customer_group='Store Customers';
run;quit;

%macro test(param);

    proc print data=customer;
    where customer_group="&amp;amp;param";
    %if "&amp;amp;param" ="A members" %then %do;
        title "the most abudant  group is %upcase(&amp;amp;param)";
    %end;
    %else %do;
        title "the least abudant group is %upcase(&amp;amp;param)";
    %end;
    var name sex age customer_group;
    run;quit;
run;
%mend test;


options mprint mlogic;
%let least=Internet/Catalog Customers;
%test(&amp;amp;least);


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 26 Feb 2017 23:27:07 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2017-02-26T23:27:07Z</dc:date>
    <item>
      <title>Pass a parameter in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336018#M272406</link>
      <description>&lt;P&gt;I have a macro paragram.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(param);
    proc print data=customer;
    where customer_group="&amp;amp;param";
    %if &amp;amp;param=A members %then %do;
        title "the most abudant  group is %upcase(&amp;amp;param)";
    %end;
    %else %do;
        title "the least abudant group is %upcase(&amp;amp;param)";
    %end;
    var name gender age customer_group;
    
run;
%mend test;
options mprint mlogic;
&lt;BR /&gt;&lt;SPAN style="color: #000000; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; display: inline !important; float: none;"&gt;%let least=Internet/Catalog Customers;&lt;/SPAN&gt;
%test(&amp;amp;least);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I get an error:&lt;/P&gt;&lt;PRE&gt;MPRINT(TEST):   where customer_group="Internet/Catalog Customers";
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
       is required. The condition was: &amp;amp;param=A members&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Feb 2017 21:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336018#M272406</guid>
      <dc:creator>sas_newbie3</dc:creator>
      <dc:date>2017-02-26T21:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a parameter in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336021#M272407</link>
      <description>&lt;P&gt;Have you tried changing&lt;/P&gt;&lt;PRE&gt;%if &amp;amp;param=A members %then %do;&lt;/PRE&gt;&lt;P&gt;to&lt;/P&gt;&lt;PRE&gt;%if "&amp;amp;param"=A members %then %do;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 21:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336021#M272407</guid>
      <dc:creator>galtay</dc:creator>
      <dc:date>2017-02-26T21:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a parameter in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336031#M272408</link>
      <description>&lt;P&gt;Thanks. It works. I just also wonder if I pass the the variable directly. Say&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%test(least);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Rather than&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%test(&amp;amp;least);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it possible?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 21:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336031#M272408</guid>
      <dc:creator>sas_newbie3</dc:creator>
      <dc:date>2017-02-26T21:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a parameter in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336033#M272409</link>
      <description>&lt;P&gt;dont know.&amp;nbsp; I'm probably more of a SAS newb than you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; I just did a little pattern recognition on your code.&amp;nbsp; In some places the variable had quotes around it and in others it didn't.&amp;nbsp; seemed reasonable to assume that was where the problem was.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 21:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336033#M272409</guid>
      <dc:creator>galtay</dc:creator>
      <dc:date>2017-02-26T21:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a parameter in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336035#M272410</link>
      <description>&lt;P&gt;The reason I asked is I want to reference the parameter into the tite statement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title "the least abudant group is %upcase(&amp;amp;param)"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to replace the word "least" in the title statement with the param as they are same words.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 22:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336035#M272410</guid>
      <dc:creator>sas_newbie3</dc:creator>
      <dc:date>2017-02-26T22:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a parameter in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336062#M272411</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Pass a parameter in macro

When this is resolved Internet/Catalog Customers
your program tries to do a division,

I almost always double quote my macro comparison arguments.


HAVE
====

Up to 40 obs WORK.CUSTOMER total obs=5

Obs     NAME      SEX    CUSTOMER_GROUP

 1     Alfred      M     Store Customers
 2     Alice       F     Store Customers
 3     Barbara     F     Internet/Catalog Customers
 4     Carol       F     Store Customers
 5     Henry       M     Store Customers


WANT
====

the least abudant group is INTERNET/CATALOG CUSTOMERS

Obs     NAME      SEX    AGE          CUSTOMER_GROUP

 3     Barbara     F      13    Internet/Catalog Customers

BUT I GET THE ERRO


MPRINT(TEST):   where customer_group="Internet/Catalog Customers";
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
       is required. The condition was: &amp;amp;param=A members

WITH THIS CODE
==============

%macro test(param);
    proc print data=customer;
    where customer_group="&amp;amp;param";
    %if &amp;amp;param=A members %then %do;
        title "the most abudant  group is %upcase(&amp;amp;param)";
    %end;
    %else %do;
        title "the least abudant group is %upcase(&amp;amp;param)";
    %end;
    var name gender age customer_group;

run;
%mend test;
options mprint mlogic;
%let least=Internet/Catalog Customers;
%test(&amp;amp;least);


WORKING CODE
============

Change

   %if &amp;amp;param =A members %then %do;

to

  %if "&amp;amp;param" ="A members" %then %do;

Also she need a run;quit;

FULL SOLUTION
=============

data customer( keep=name sex age customer_group);
  set sashelp.class(obs=5);
  if name='Barbara' then customer_group ='Internet/Catalog Customers';
  else customer_group='Store Customers';
run;quit;

%macro test(param);

    proc print data=customer;
    where customer_group="&amp;amp;param";
    %if "&amp;amp;param" ="A members" %then %do;
        title "the most abudant  group is %upcase(&amp;amp;param)";
    %end;
    %else %do;
        title "the least abudant group is %upcase(&amp;amp;param)";
    %end;
    var name sex age customer_group;
    run;quit;
run;
%mend test;


options mprint mlogic;
%let least=Internet/Catalog Customers;
%test(&amp;amp;least);


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Feb 2017 23:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336062#M272411</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-02-26T23:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a parameter in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336160#M272412</link>
      <description>&lt;P&gt;I am not sure what the value is in this whole bit of code. &amp;nbsp;The only part which actually changes is the word most or least, so why not evaluate than and drop all the rest of it? &amp;nbsp;E.g.&lt;/P&gt;
&lt;PRE&gt;data _null_;
  call symputx('word',ifc("&amp;amp;param."="A members","most","least"));
run;

title "The &amp;amp;word. abundant group is %upcase(&amp;amp;param.)";

proc print data=customer;
  where customer_group="&amp;amp;param.";
  var name gender age customer_group;
run;
  &lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Feb 2017 11:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-a-parameter-in-macro/m-p/336160#M272412</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-27T11:34:31Z</dc:date>
    </item>
  </channel>
</rss>

