<?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: How to skip a step if the nested loop for a macro variable is empty? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549225#M152375</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/211980"&gt;@Sami1234&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've only posted a SAS macro code snippet so how do you expect us to know anything about "&lt;EM&gt;If any of the variable from list1 is not in the input dataset or misspelled&lt;/EM&gt;" and how this would affect your processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always query the SAS dictionary tables (dictionary.columns) to determine if variable names listed as text (words) in a macro variable also exist in the actual data set - and then branch to some exception logic in case you find discrepancies.&lt;/P&gt;
&lt;P&gt;You would likely implement such a check before you start the macro do loops you've posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below just showcasing what I'm talking about.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo(varlist);
  %let varlist_quotesAndcomma="%sysfunc(prxchange(s/\s+/%nrbquote(",")/i,-1,&amp;amp;varlist))";
  %put &amp;amp;=varlist_quotesAndcomma;
  proc sql noprint;
    select count(*) into :nvars
    from dictionary.columns
    where libname='SASHELP' and memname='CLASS' and upcase(name) in (%upcase(&amp;amp;varlist_quotesAndcomma))
    ;
  quit;

  %if &amp;amp;nvars ne %sysfunc(countw(&amp;amp;varlist)) %then
    %do;
      %put Branch to exception logic;
    %end;
  %else
    %put Branch to standard logic;
%mend;
%demo(name sex height);
%demo(name sex heigt);
&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, 08 Apr 2019 12:23:23 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-04-08T12:23:23Z</dc:date>
    <item>
      <title>How to skip a step if the nested loop for a macro variable is empty?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549212#M152371</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you please help me with the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the sublist is empty or blank, how can it be the tackle&amp;nbsp;in the following&amp;nbsp;code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;i =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(countw(&amp;amp;list1));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;j =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(countw(&amp;amp;sublist));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;main&amp;amp;i. =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;list1,&amp;amp;i,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;( ));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;sub&amp;amp;j. =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;sublist,&amp;amp;j,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;( ));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;amp;&amp;amp;main&amp;amp;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;= &amp;amp;&amp;amp;sub&amp;amp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;j.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008000"&gt;/*Some steps */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%else&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/**other steps**/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thank you!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 10:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549212#M152371</guid>
      <dc:creator>Sami1234</dc:creator>
      <dc:date>2019-04-08T10:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to skip a step if the nested loop for a macro variable is empty?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549213#M152372</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/211980"&gt;@Sami1234&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I figured out the following by trying so "making up" the explanation. If the macro variable is empty then "something" must still tell the countw() function that a string has been passed in. When I've used the %str() function then things worked for me - I guess that's because %str() adds some hidden quoting characters so the string countw() gets is not really empty (because when also adding %unquote()&amp;nbsp; around the %str() function SAS throws again an Error).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(sublist);
  %do j = 1 %to %sysfunc(countw(%str(&amp;amp;sublist)));
    %put XXXXXXXXXXX;
  %end;
%mend;
%test(test);
%test(test blah);
%test();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2019 10:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549213#M152372</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-04-08T10:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to skip a step if the nested loop for a macro variable is empty?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549214#M152373</link>
      <description>&lt;P&gt;Sorry, I would like to add one more condition and how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1: If the sublist is empty or blank, how can it be the tackle&amp;nbsp;in the following&amp;nbsp;code?&lt;/P&gt;&lt;P&gt;2: If any of the variable from list1 is not in the input dataset or misspelled, how to end the macro and come off without running any further steps?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;i =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(countw(&amp;amp;list1));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;j =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(countw(&amp;amp;sublist));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;main&amp;amp;i. =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;list1,&amp;amp;i,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;( ));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;sub&amp;amp;j. =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;sublist,&amp;amp;j,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;( ));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;amp;&amp;amp;main&amp;amp;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;= &amp;amp;&amp;amp;sub&amp;amp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;j.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008000"&gt;/*Some steps */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%else&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/**other steps**/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thank you!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 11:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549214#M152373</guid>
      <dc:creator>Sami1234</dc:creator>
      <dc:date>2019-04-08T11:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to skip a step if the nested loop for a macro variable is empty?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549225#M152375</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/211980"&gt;@Sami1234&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've only posted a SAS macro code snippet so how do you expect us to know anything about "&lt;EM&gt;If any of the variable from list1 is not in the input dataset or misspelled&lt;/EM&gt;" and how this would affect your processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always query the SAS dictionary tables (dictionary.columns) to determine if variable names listed as text (words) in a macro variable also exist in the actual data set - and then branch to some exception logic in case you find discrepancies.&lt;/P&gt;
&lt;P&gt;You would likely implement such a check before you start the macro do loops you've posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below just showcasing what I'm talking about.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo(varlist);
  %let varlist_quotesAndcomma="%sysfunc(prxchange(s/\s+/%nrbquote(",")/i,-1,&amp;amp;varlist))";
  %put &amp;amp;=varlist_quotesAndcomma;
  proc sql noprint;
    select count(*) into :nvars
    from dictionary.columns
    where libname='SASHELP' and memname='CLASS' and upcase(name) in (%upcase(&amp;amp;varlist_quotesAndcomma))
    ;
  quit;

  %if &amp;amp;nvars ne %sysfunc(countw(&amp;amp;varlist)) %then
    %do;
      %put Branch to exception logic;
    %end;
  %else
    %put Branch to standard logic;
%mend;
%demo(name sex height);
%demo(name sex heigt);
&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, 08 Apr 2019 12:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549225#M152375</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-04-08T12:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to skip a step if the nested loop for a macro variable is empty?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549314#M152396</link>
      <description>&lt;P&gt;Thank you so much, its working perfectly fine now &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 15:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549314#M152396</guid>
      <dc:creator>Sami1234</dc:creator>
      <dc:date>2019-04-08T15:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to skip a step if the nested loop for a macro variable is empty?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549348#M152417</link>
      <description>&lt;P&gt;To prevent errors from %SYSFUNC() you can just add a comma.&lt;/P&gt;
&lt;PRE&gt;645   %let x=;
646   %put %sysfunc(countw(&amp;amp;x));
ERROR: The function COUNTW referenced by the %SYSFUNC or %QSYSFUNC macro function has too few arguments.
.
647   %put %sysfunc(countw(&amp;amp;x,));
0
&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2019 17:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549348#M152417</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-08T17:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to skip a step if the nested loop for a macro variable is empty?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549683#M152554</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;if I put 'Comma', it's not throwing any error at all and skipping the whole macro.&lt;/P&gt;&lt;P&gt;But I would like to achieve&amp;nbsp;something as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;list1 contains a list of continuous and categorical variables altogether &amp;amp; sublist contains only continuous variables. So if the variable in the sublist is empty, it's not running either step, so If I put %let sublist=%str(blank); it's working fine.&lt;/P&gt;&lt;P&gt;But if the sublist contains more then 2 variables then 'else do' step runs&amp;nbsp;twice.&lt;/P&gt;&lt;P&gt;Would it be possible to put a stop or condition on the loop that it should&amp;nbsp;only run once for list1 variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;i =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(countw(&amp;amp;list1));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;j =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(countw(&amp;amp;sublist));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;main&amp;amp;i. =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;list1,&amp;amp;i,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;( ));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;sub&amp;amp;j. =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;sublist,&amp;amp;j,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;( ));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;amp;&amp;amp;main&amp;amp;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;= &amp;amp;&amp;amp;sub&amp;amp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;j.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008000"&gt;/*Some steps */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%else&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/**other steps**/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-skip-a-step-if-the-nested-loop-for-a-macro-variable-is/m-p/549683#M152554</guid>
      <dc:creator>Sami1234</dc:creator>
      <dc:date>2019-04-09T16:14:40Z</dc:date>
    </item>
  </channel>
</rss>

