<?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: mask commas in a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926688#M364685</link>
    <description>&lt;P&gt;&amp;nbsp;Why over complicate things? There is no need to place the where condition "ON" either the input or the output dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use a normal WHERE statement instead of the WHERE= dataset option.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro makereport(Var=, Check=);
data OUTPUT ;
  set SASHELP.CARS;
  where Origin IN (&amp;amp;Check);
  &amp;amp;Var;
run;
%mend makereport;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 01 May 2024 20:14:32 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-05-01T20:14:32Z</dc:date>
    <item>
      <title>mask commas in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926635#M364656</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to pass commas in a macro function and I get the below error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: All positional parameters must precede keyword parameters.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I understand to mask the commas %BQUOTE should be the best solution, but I cannot see how to apply this to my code&amp;nbsp; - below.&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;/*real file will come from an Excel import*/
data INFILE;
	input if_statement $ 1-36 Region $ 37-60;
	datalines;
1 if Make = 'Audi' then TEST1 = 'OK' 'Europe', 'Asia', 'USA'
2 if Make = 'BMW' then TEST2 = 'OK'  'Asia', 'USA'
3 if Make = 'Ford' then TEST3 = 'OK' 'USA', 'Asia'
;
run;

%macro makereport(Var=, Check=);

    /*run test*/
	data OUTPUT (where=(Origin IN (&amp;amp;Check)));
		set SASHELP.CARS;
		&amp;amp;Var;
	run;

%put &amp;amp;Var;
%put &amp;amp;Check;

/*additional steps to retain/store results will go here*/

%mend makereport;

data _null_;
	set INFILE;

	*builds string to execute macro;
str = catt('%makereport(Var=',if_statement,',Check=',Region,');');

	*execute macro;
	call execute(str);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have looked at many examples on the web, but none I can see where it should be applied to a code like mine (at least as I understand it):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried adding to&amp;nbsp; the&amp;nbsp;call execute, the&amp;nbsp;string that builds the macro and within the macro (though I believe it's incorrect anyway) but none of this works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 16:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926635#M364656</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2024-05-01T16:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: mask commas in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926644#M364663</link>
      <description>&lt;P&gt;I strongly advise you to consider a simpler approach, which does not involve all three of: SAS code stored in a data set, macros and call execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end, I doubt this will work because it does not resolve to working SAS data step code. But I don't really know what actual SAS data step code you want here, you have not told us. So, &lt;STRONG&gt;without macros and without macro variables&lt;/STRONG&gt;, show us what SAS code you want here for row 1 of the data set (or any single row), show us working SAS code that does what you want. Fill in the blanks for one case, without macros and without macro variables. Without working code here, you will never get macros and call execute to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	data OUTPUT (where=(Origin IN (______________)));
		set SASHELP.CARS;
                _________________________________________
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my past experience, people just sidestep or ignore the question, and never provide working code here without macros and without macro variables. Please don't sidestep or ignore the question.&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 17:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926644#M364663</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-01T17:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: mask commas in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926650#M364668</link>
      <description>&lt;P&gt;The IN operator will accept blank delimited lists.&amp;nbsp; No comma needed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if region in('Europe' 'Asia' 'USA')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 17:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926650#M364668</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-05-01T17:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: mask commas in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926660#M364671</link>
      <description>&lt;P&gt;Hi, in addition to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; very good suggestion, it also helps to understand the basics of using WHERE with IN. For example, a simple test or reading the documentation&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1714585618128.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96101i4CD12CE2CADAA0E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1714585618128.png" alt="Cynthia_sas_1-1714585618128.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;would show that commas are not required with the IN operator. Your list for the IN operator can be separated by blanks. In addition, putting the WHERE on the DATA statement forces ALL of the observations to be read (causing more I/O) especially if you're only choosing a subset of the entire input data. Putting the WHERE on the SET statement with the INPUT data is usually more efficient, which is why you start with working code before writing any macro code.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1714585400616.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96100i271A83F50EEB1E75/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1714585400616.png" alt="Cynthia_sas_0-1714585400616.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Hope this helps.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 17:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926660#M364671</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-05-01T17:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: mask commas in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926686#M364684</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; very helpful - I have amended the code to remove commas and place the where in the SET - now it work fine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*real file will come from an Excel import*/
data INFILE;
	input if_statement $ 1-36 Region $ 37-60;
	datalines;
if Make = 'BMW'  then TEST2 = 'OK'  'Asia'  'USA'
if Make = 'Ford' then TEST3 = 'OK'  'USA'  'Asia'
if Make = 'Audi' then TEST1 = 'OK'  'Europe'  'Asia'  'USA'
;
run;

%macro makereport(Var=, Check=);

    /*run test*/
	data OUTPUT ;
		set SASHELP.CARS (where=(Origin IN (&amp;amp;Check)));
		&amp;amp;Var;
	run;

%put var=&amp;amp;Var;
%put check=&amp;amp;Check;

/*additional steps to retain/store results will go here*/

%mend makereport;

data _null_;
	set INFILE;

	*builds string to execute macro;
str = catt('%makereport(Var=',if_statement,';,Check=',Region,');');

	*execute macro;
	call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; re what I need, the above will do - after I add more tables in the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;. In brief, I have a dataset where different users need to run different tests against (i.e. how many records in Column1 are greater than records in Column2, only for records with some values in Column3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Users&lt;/P&gt;
&lt;P&gt;-enter those tests in Excel (i.e. COL1&amp;gt;COL2 where COL3 IN (blue&amp;nbsp; white black) )&lt;/P&gt;
&lt;P&gt;- import the file where SAS converts into the str&lt;/P&gt;
&lt;P&gt;- the macro will add a column for each test - putting them together in a table using PROC APPEND or similar&lt;/P&gt;
&lt;P&gt;-additional tables within the macro will summarise the result in a summary table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought the macro approach would be the best, but happy to consider anything else ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 20:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926686#M364684</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2024-05-01T20:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: mask commas in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926688#M364685</link>
      <description>&lt;P&gt;&amp;nbsp;Why over complicate things? There is no need to place the where condition "ON" either the input or the output dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use a normal WHERE statement instead of the WHERE= dataset option.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro makereport(Var=, Check=);
data OUTPUT ;
  set SASHELP.CARS;
  where Origin IN (&amp;amp;Check);
  &amp;amp;Var;
run;
%mend makereport;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 May 2024 20:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926688#M364685</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-01T20:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: mask commas in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926739#M364706</link>
      <description>&lt;P&gt;...and below how you could call the macro in case Region contains a comma separated list of values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*real file will come from an Excel import*/
data driver;
	input if_statement $ 1-36 Region $ 37-60;
	datalines;
if Make = 'BMW'  then TEST2 = 'OK'  'Asia','USA'
if Make = 'Ford' then TEST3 = 'OK'  'USA'  'Asia'
if Make = 'Audi' then TEST1 = 'OK'  'Europe'  'Asia'  'USA'
;
run;

%macro makereport(Var=, Check=);
data OUTPUT ;
  set SASHELP.CARS;
  where Origin IN (&amp;amp;Check);
  &amp;amp;Var;
run;
%mend makereport;

data _null_;
	set driver;
	*builds string to execute macro;
  str = catt('%makereport(Var=',if_statement,',Check=%nrbquote(',Region,'));');
	*execute macro;
	call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2024 06:39:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mask-commas-in-a-macro-variable/m-p/926739#M364706</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-02T06:39:59Z</dc:date>
    </item>
  </channel>
</rss>

