<?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: A Macro function for validating countries - Unexpected &amp;quot;hole&amp;quot; in the error catching in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/762083#M241247</link>
    <description>&lt;P&gt;Issue was mismatched %IF/%ELSE.&lt;/P&gt;
&lt;P&gt;Try this update:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %if not %length(&amp;amp;countrym) %then %do;
    %let countrynotvalidbm=1;
    %put ERROR: COUNTRYM value cannot be empty. ;
  %end;
  %else %if not (%qupcase(&amp;amp;countrym) in &amp;amp;listm) %then %do;
      %let countrynotvalidbm=1;
      %put ERROR: COUNTRYM value "&amp;amp;countrym." must be ONE of the values: &amp;amp;listm .;
  %end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will treat 0 (or missing) as FALSE and any other number as TRUE.&amp;nbsp; So no need to add the extra characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Aug 2021 15:11:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-08-17T15:11:20Z</dc:date>
    <item>
      <title>A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761765#M241093</link>
      <description>&lt;P&gt;I have written a function to validate wether a country is in a specific list of the nordic countries (SE DK NO FI).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So for example,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put test = %ValidateCountry(se, no fi); &amp;nbsp;#returns&amp;nbsp;the&amp;nbsp;logical 1.&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The whole function looks like this (For the variables, &lt;STRONG&gt;b&lt;/STRONG&gt; stands for boolean and &lt;STRONG&gt;m&lt;/STRONG&gt; stands for macro. Example: country&lt;STRONG&gt;m &lt;/STRONG&gt;indicates that the variable is a macro variable).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;%macro ValidateCountry(countrym /* Choose SE, DK, NO or FI. */, 
							countrylistm /* A used defined list contaning a combination of SE, DK, NO, FI. */
							 ) /minoperator mindelimiter=' ';

/*--------------------------------------------------------------*/
/*Help Functionality*/
/*--------------------------------------------------------------*/
	%if %upcase(&amp;amp;countrym.)= HELP or &amp;amp;countrym.=? %then %do;
	    %put WARNING-************************************************************************;
	    %put WARNING-*   Description: Validate a country, the function is case-insensitive. *;
	    %put WARNING-*   Syntax: ValidateCountry(countrym, countrylistm, caseb).            *;
	    %put WARNING-*   Parameters:                                                        *;
	    %put WARNING-*     countrym: One of SE, DK, NO, FI.                                 *;
	    %put WARNING-*     countrylistm: a combination of SE, DK, NO, FI.                   *;
	    %put WARNING-*    ----------------------------------------------------------------  *;
	    %put WARNING-*      Example 1: ValidateCountry(SE, SE NO) returns 1.                *;
	    %put WARNING-*      Example 2: ValidateCountry(nO, sE NO Fi) returns 1.             *;
	    %put WARNING-*      Example 3: ValidateCountry(SE, SE USA) returns error.           *;
	    %put WARNING-************************************************************************;
	    %return;
	%end;

/*--------------------------------------------------------------*/
/*Validation*/
/*--------------------------------------------------------------*/
	%local countrynotvalidbm countrylistnotvalidbm i nextm listm validbm;

	%let countrynotvalidbm = 0;   /* Initializing the variables used below */
	%let countrylistnotvalidbm = 0; 
	%let validbm = 0; 

	%let listm=%qupcase(SE DK NO FI);

	%if not (%qupcase(&amp;amp;countrym) in &amp;amp;listm) %then %do;
		%let countrynotvalidbm=1;
		%put ERROR: COUNTRY value "&amp;amp;countrym." must be ONE of the values: &amp;amp;listm .;
	%end;

	%do i=1 %to %sysfunc(countw(&amp;amp;countrylistm.));
		%let nextm=%qscan(&amp;amp;countrylistm.,&amp;amp;i,%str( ));

		%if not (%qupcase(&amp;amp;nextm) in &amp;amp;listm) %then %do;
		   %let countrylistnotvalidbm=1;
		   %put ERROR: COUNTRYLIST value "&amp;amp;nextm" is not among the values: &amp;amp;listm. ;
		%end;
	%end;

/*--------------------------------------------------------------*/
/*Main Body*/
/*--------------------------------------------------------------*/
	%if (&amp;amp;countrynotvalidbm. = 1 or &amp;amp;countrylistnotvalidbm. = 1) %then %do ; 
		%put ERROR: The function was not run due to errors. ; 
	%end;
 
	%else %do;
		%if %upcase(&amp;amp;countrym.) in %upcase(&amp;amp;countrylistm.) %then %do; 
	 		%let validbm= 1; 
		%end; 
	%end; 

	&amp;amp;validbm. ; /*1 if the country is in the valid list */

%mend; &lt;/PRE&gt;
&lt;P&gt;Now, running code below yields an error. I was hoping that the validation part of the function would catch it, but it does not. Error messages appearing are:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%put test = %ValidateCountry(,se no); 

/* The following error appears */
ERROR: Operand missing for IN operator in argument to %EVAL function.
ERROR: The macro VALIDATECOUNTRY will stop executing.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%put test = %ValidateCountry(se , );&lt;BR /&gt;&lt;BR /&gt;/* The following error appears */&lt;BR /&gt;ERROR: The function COUNTW referenced by the %SYSFUNC or %QSYSFUNC macro function has too few arguments.&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt;%sysfunc(countw(&amp;amp;countrylistm.)) &lt;BR /&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;BR /&gt;ERROR: The macro VALIDATECOUNTRY will stop executing.&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;I don't know how to solve this "hole" in the error handling. All advice much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 10:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761765#M241093</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-08-16T10:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761770#M241098</link>
      <description>&lt;P&gt;You will find that the macro IN operator will fail and throw an error if a NULL value is presented to the operator on either side. The way your macro is constructed, you are expecting either a single value in &lt;STRONG&gt;countrym&lt;/STRONG&gt; or a list in &lt;STRONG&gt;countrylistm&lt;/STRONG&gt;. This means that one of those values will always be NULL. In the body of the macro, both values are always tested with an IN operator, so the IN operator is always exposed to a NULL value. Hence the errors you are seeing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May the SAS be with you!&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 11:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761770#M241098</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-08-16T11:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761779#M241101</link>
      <description>&lt;P&gt;Do you have parentheses around your list after your in operator? Submitting to you with out testing, I think this is what you are lacking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	%else %do;
		%if %upcase(&amp;amp;countrym.) in ( %upcase(&amp;amp;countrylistm.) ) %then %do; 
                                         /**/                       /**/
	 		%let validbm= 1; 
		%end; 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 12:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761779#M241101</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-08-16T12:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761784#M241104</link>
      <description>&lt;P&gt;For testing for blank macro variables, I would recommend:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings09/022-2009.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings09/022-2009.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which will allow you to do stuff like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %isblank(countrym) %then %do;
  %put ERROR: CountryM parameter is required. ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 12:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761784#M241104</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-08-16T12:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761796#M241111</link>
      <description>&lt;P&gt;Issues:&lt;/P&gt;
&lt;P&gt;Test for empty values.&lt;/P&gt;
&lt;P&gt;Include the delimiter in the call to COUNTW().&lt;/P&gt;
&lt;P&gt;Use macro quoting consistently.&amp;nbsp; The last IN operation did not macro quote the value being tested.&lt;/P&gt;
&lt;P&gt;Do not emit the semi-colon as part of the macro results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And on formatting :&lt;/P&gt;
&lt;P&gt;- do not include physical tab characters into code files.&amp;nbsp; It causes things like this when opened by programs that are using different tab stops than you thought.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62625iEFDD3472E0A987F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;- place continuation characters on multi-line statements at the START of the line, not the END of the line so that humans scanning the file can see them.&lt;/P&gt;
&lt;P&gt;- Make the parameter names in your error messages match the parameter names in the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ValidateCountry
(countrym       /* Choose SE, DK, NO or FI. */
,countrylistm   /* A used defined list contaning a combination of SE, DK, NO, FI. */
) /minoperator mindelimiter=' ';

/*--------------------------------------------------------------*/
/*Help Functionality*/
/*--------------------------------------------------------------*/
  %if %upcase(&amp;amp;countrym.)= HELP or &amp;amp;countrym.=? %then %do;
      %put WARNING-************************************************************************;
      %put WARNING-*   Description: Validate a country, the function is case-insensitive. *;
      %put WARNING-*   Syntax: ValidateCountry(countrym, countrylistm, caseb).            *;
      %put WARNING-*   Parameters:                                                        *;
      %put WARNING-*     countrym: One of SE, DK, NO, FI.                                 *;
      %put WARNING-*     countrylistm: a combination of SE, DK, NO, FI.                   *;
      %put WARNING-*    ----------------------------------------------------------------  *;
      %put WARNING-*      Example 1: ValidateCountry(SE, SE NO) returns 1.                *;
      %put WARNING-*      Example 2: ValidateCountry(nO, sE NO Fi) returns 1.             *;
      %put WARNING-*      Example 3: ValidateCountry(SE, SE USA) returns error.           *;
      %put WARNING-************************************************************************;
      %return;
  %end;

/*--------------------------------------------------------------*/
/*Validation*/
/*--------------------------------------------------------------*/
  %local countrynotvalidbm countrylistnotvalidbm i nextm listm validbm;

  %let countrynotvalidbm = 0;   /* Initializing the variables used below */
  %let countrylistnotvalidbm = 0; 
  %let validbm = 0; 

  %let listm=%qupcase(SE DK NO FI);

  %if %length(&amp;amp;countrym) %then %if not (%qupcase(&amp;amp;countrym) in &amp;amp;listm) %then %do;
    %let countrynotvalidbm=1;
    %put ERROR: COUNTRYM value "&amp;amp;countrym." must be ONE of the values: &amp;amp;listm .;
  %end;
  %else %do;
    %let countrynotvalidbm=1;
    %put ERROR: COUNTRYM value cannot be empty. ;
  %end;

  %let i=%sysfunc(countw(&amp;amp;countrylistm.,%str( )));
  %if &amp;amp;i %then %do i=1 %to &amp;amp;i;
    %let nextm=%qscan(&amp;amp;countrylistm.,&amp;amp;i,%str( ));

    %if not (%qupcase(&amp;amp;nextm) in &amp;amp;listm) %then %do;
       %let countrylistnotvalidbm=1;
       %put ERROR: COUNTRYLISTM value "&amp;amp;nextm" is not among the values: &amp;amp;listm. ;
    %end;
  %end;
  %else %do;
       %let countrylistnotvalidbm=1;
       %put ERROR: COUNTRYLISTM value cannot be empty.;
  %end;

/*--------------------------------------------------------------*/
/*Main Body*/
/*--------------------------------------------------------------*/
  %if (&amp;amp;countrynotvalidbm. = 1 or &amp;amp;countrylistnotvalidbm. = 1) %then %do ; 
    %put ERROR: The function was not run due to errors. ; 
  %end;
 
  %else %do;
    %if %qupcase(&amp;amp;countrym.) in %upcase(&amp;amp;countrylistm.) %then %do; 
       %let validbm= 1; 
    %end; 
  %end; 

  &amp;amp;validbm.  /*1 if the country is in the valid list */

%mend ValidateCountry;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 14:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761796#M241111</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-16T14:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761798#M241113</link>
      <description>&lt;P&gt;While I can't test it (or I would), I believe you can simplify tremendously and avoid the complications ... along the lines of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let found = %sysfunc(indexw(&amp;amp;countrylistm, &amp;amp;countrym)) &amp;gt; 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You still need to apply %upcase along the way, but you don't need a macro IN operator.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 13:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761798#M241113</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-08-16T13:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761846#M241137</link>
      <description>&lt;P&gt;As an aside, personally I don't think I'd use macro quoting at all here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need quoting (or even upcasing) here because you hard-coded a string that doesn't have any symbols that need to have their meaning hidden:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let listm=%qupcase(SE DK NO FI)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I guess some folks follow the guideline of macro quoting every user parameter, in case a user enters a value like OR, NE, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I tend to only macro quote when there is a likely need (such as US state abbreviations), rather than to protect against any crazy value somebody might enter.&amp;nbsp; Of course I sometimes pay the price for that, depending on how widely a macro will be used, because I'm often surprised that people put &amp;amp; symbols in file names and other fun stuff.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 15:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761846#M241137</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-08-16T15:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761849#M241138</link>
      <description>&lt;P&gt;Good point.&amp;nbsp; It took so long for SAS to get the macro IN operator working, and the first implementations were so confusing, that I've never bothered to learn how to use it.&amp;nbsp; It still feels clunky to have to specify minoperator and mindelimiter.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 15:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761849#M241138</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-08-16T15:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761867#M241146</link>
      <description>&lt;P&gt;Is there anything wrong with using FIND()?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _=; /*@jimbarbour*/

&amp;amp;_ %macro _ValidateCountry
    (countrym       /* Choose SE, DK, NO or FI. */
    ,countrylistm   /* A used defined list contaning a combination of SE, DK, NO, FI. */
    ) /minoperator mindelimiter=' ';
  %let valid=%eval( %sysfunc(find(SE DK NO FI,&amp;amp;countrym,i)) &amp;gt; 0);
  %let return=%eval( (%sysfunc(find(&amp;amp;countrylistm,&amp;amp;countrym,i))) &amp;gt; 0 );
  %eval( &amp;amp;return * &amp;amp;valid );
%MEND;

%put %_ValidateCountry(SE, SE NO) ;      
%put %_ValidateCountry(nO, sE NO Fi);   
%put %_ValidateCountry(SE, SE USA); 
%put %_ValidateCountry(,se no); 
%put %_ValidateCountry(se , ); 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 17:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761867#M241146</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-08-16T17:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761878#M241154</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15329"&gt;@PhilC&lt;/a&gt;&amp;nbsp;, there would be a problem using FIND.&amp;nbsp; It doesn't look for words.&amp;nbsp; So if the (invalid) country code is O, for example, FIND would find it within:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SE NO FI&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 17:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761878#M241154</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-08-16T17:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761882#M241157</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15329"&gt;@PhilC&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that FINDW might work better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With FINDW, you don't need MINOPERATOR or MINDELIMITER anymore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An interesting thing that I sometimes do in macros is to assign a default while still allowing for positional parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _=; /*@jimbarbour*/

&amp;amp;_ %macro _ValidateCountry
    (countrym       /* Choose SE, DK, NO or FI. */
    ,countrylistm   /* A used defined list contaning a combination of SE, DK, NO, FI. */
    );
/*	%PUT	&amp;amp;Nte1  &amp;amp;=countrym  &amp;amp;=countrylistm;*/
	%IF	%BQUOTE()	=	%BQUOTE(&amp;amp;CountryListM)	%THEN
		%LET	CountryListM	=	SE DK NO FI;
/*	%PUT	&amp;amp;Nte1  &amp;amp;=countrym  &amp;amp;=countrylistm;*/
  %eval(%sysfunc(findw(&amp;amp;countrylistm,&amp;amp;countrym,,SI)) &amp;gt; 0);
%MEND;

OPTIONS	NOSOURCE;
%put NOTE: %_ValidateCountry(SE, SE NO) ;      
%put NOTE- %_ValidateCountry(nO, sE NO Fi);   
%put NOTE- %_ValidateCountry(SE, SE USA); 
%put NOTE- %_ValidateCountry(,se no); 
%put NOTE- %_ValidateCountry(se , ); 
%put NOTE- %_ValidateCountry( , NE); 
%put NOTE- %_ValidateCountry(NO , NE); 
%put NOTE- %_ValidateCountry(o , ); 
OPTIONS	SOURCE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;In the above, the first %BQUOTE is not really necessary, but sometimes is helpful to me just in terms of readability.&amp;nbsp; The second %BQUOTE is actually doing something.&amp;nbsp; Try running the code with and without the %BQUOTE, but uncomment the %PUT&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%PUT	&amp;amp;Nte1  &amp;amp;=countrym  &amp;amp;=countrylistm;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before and after the %IF statement and run with parameters (NO, NE)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put NOTE- %_ValidateCountry(NO , NE); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 18:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/761882#M241157</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-16T18:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/762081#M241245</link>
      <description>&lt;P&gt;Thank you very much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; .&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;"&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;- place continuation characters on multi-line statements at the START of the line, not the END of the line so that humans scanning the file can see them."&lt;/EM&gt; What do you mean by this?&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Running the code you provided, I got the following obviously wrong (Non desirable) answers when running the code (indicating the function is wrong):&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1. 
%let test=%ValidateCountry(,SE DK);  /* Should be COUNTRYM value cannot be empty. */ 

ERROR: Operand missing for IN operator in argument to %EVAL function.
ERROR: The macro VALIDATECOUNTRY will stop executing. 

2. 
%let test=%ValidateCountry(SE, ); 

ERROR: COUNTRYM value cannot be empty.
ERROR: COUNTRYLISTM value cannot be empty.
ERROR: The function was not run due to errors.

3. 
%put test = %ValidateCountry(sE, UK SE); /* OK */

ERROR: COUNTRYM value cannot be empty.
ERROR: COUNTRYLISTM value "UK" is not among the values: SE DK NO FI
ERROR: The function was not run due to errors.

4. 
%put test = %ValidateCountry(se, UK USA SE); /* OK */

ERROR: COUNTRYM value cannot be empty.
ERROR: COUNTRYLISTM value "UK" is not among the values: SE DK NO FI
ERROR: COUNTRYLISTM value "USA" is not among the values: SE DK NO FI
ERROR: The function was not run due to errors.

5. 
%put test = %ValidateCountry(se, no); /* OK */

ERROR: COUNTRYM value cannot be empty.
ERROR: The function was not run due to errors.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the code line:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%if %length(&amp;amp;countrym)&lt;/PRE&gt;
&lt;P&gt;does it actually mean:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%if %length(&amp;amp;countrym) &amp;gt; 0 ?&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Thanks alot.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 15:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/762081#M241245</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-08-17T15:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/762083#M241247</link>
      <description>&lt;P&gt;Issue was mismatched %IF/%ELSE.&lt;/P&gt;
&lt;P&gt;Try this update:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %if not %length(&amp;amp;countrym) %then %do;
    %let countrynotvalidbm=1;
    %put ERROR: COUNTRYM value cannot be empty. ;
  %end;
  %else %if not (%qupcase(&amp;amp;countrym) in &amp;amp;listm) %then %do;
      %let countrynotvalidbm=1;
      %put ERROR: COUNTRYM value "&amp;amp;countrym." must be ONE of the values: &amp;amp;listm .;
  %end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will treat 0 (or missing) as FALSE and any other number as TRUE.&amp;nbsp; So no need to add the extra characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 15:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/762083#M241247</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-17T15:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro function for validating countries - Unexpected "hole" in the error catching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/762092#M241248</link>
      <description>&lt;P&gt;You need to provide what logic you want to do as this case appears to be working as your original macro intended.&lt;/P&gt;
&lt;PRE&gt;929   %put test = %ValidateCountry(se, UK USA SE);
ERROR: COUNTRYLISTM value "UK" is not among the values: SE DK NO FI
ERROR: COUNTRYLISTM value "USA" is not among the values: SE DK NO FI
ERROR: The function was not run due to errors.
test = 0
&lt;/PRE&gt;
&lt;P&gt;Those two values are clearly NOT in the list of valid values your macro defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use COUNTRYLISTM as an OVERRIDE for the hardcoded list of valid value why did you include that test to begin with?&amp;nbsp; That is much easier to code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let listm=%qupcase(SE DK NO FI);
%if %length(&amp;amp;countrylistm) %then %let listm=%qupcase(&amp;amp;countrylistm);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And now there is no need to "test" COUNTRYLISTM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 15:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-function-for-validating-countries-Unexpected-quot-hole/m-p/762092#M241248</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-17T15:19:10Z</dc:date>
    </item>
  </channel>
</rss>

