<?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: issue with %if %then %else %if in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417169#M102466</link>
    <description>&lt;P&gt;Make sure you have %END statements for your %DO statements. Same for your DO and END statement in the SAS code your macrro is generating.&lt;/P&gt;
&lt;P&gt;Consistent indentation helps.&amp;nbsp; I like the treat the nesting of macro code and generated SAS code separate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let suppvar_list=;
%if &amp;amp;suppvar_list. ne %then %do;
  %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list.));
    &lt;FONT color="#FF0000"&gt;%* WHAT GOES HERE ? ;&lt;/FONT&gt;
  %end;
&lt;FONT color="#FF0000"&gt;%end;&lt;/FONT&gt;
%else %do;
  %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list,%str()));
    &lt;FONT color="#FF0000"&gt;%* WHAT GOES HERE ? ;&lt;/FONT&gt;
  %end;  
  %let curr_var = %scan(&amp;amp;suppvar_list., &amp;amp;j.);
if not missing(&amp;amp;curr_var.) then do;
  QNAM = upcase(vname(&amp;amp;curr_var.));
&lt;FONT color="#FF0000"&gt;end;&lt;/FONT&gt;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You probably want something more like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let suppvar_list=;
%if &amp;amp;suppvar_list. ne %then %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list.));
  %let curr_var = %scan(&amp;amp;suppvar_list., &amp;amp;j.);
if not missing(&amp;amp;curr_var.) then QNAM = upcase(vname(&amp;amp;curr_var.)) ;
%end;
%else %do;
QNAM=' ';
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;So if you pass in a list of two variables you generate this SAS code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not missing(VAR1) then QNAM = upcase(vname(VAR1)) ;
if not missing(VAR2) then QNAM = upcase(vname(VAR2)) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So it looks like you want to set QNAM to the name of the last variable that had a non-missing value.&lt;/P&gt;
&lt;P&gt;Not sure what the UPCASE(VNAME()) is doing, but perhaps the values in your original macro variables are array references?&lt;/P&gt;</description>
    <pubDate>Wed, 29 Nov 2017 18:07:14 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-11-29T18:07:14Z</dc:date>
    <item>
      <title>issue with %if %then %else %if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417073#M102429</link>
      <description>&lt;P&gt;I am using the below code that is if suppvar_list has no observation than use the first condition and if it has then second one but it fails&lt;/P&gt;&lt;PRE&gt;ERROR: There is no matching %IF statement for the %ELSE.&lt;BR /&gt;ERROR: A dummy macro will be compiled.&lt;BR /&gt;&lt;BR /&gt;%let suppvar_list=;

 %if &amp;amp;suppvar_list. ne %then %do;
       %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list.));
%end;
%else %do;
        %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list,%str()));
%end;  &lt;BR /&gt;   %let curr_var = %scan(&amp;amp;suppvar_list., &amp;amp;j.);&lt;BR /&gt;    if not missing(&amp;amp;curr_var.) then do;&lt;BR /&gt;    QNAM = upcase(vname(&amp;amp;curr_var.));&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AM i doing anything wrong&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 14:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417073#M102429</guid>
      <dc:creator>mj5</dc:creator>
      <dc:date>2017-11-29T14:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: issue with %if %then %else %if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417077#M102431</link>
      <description>&lt;P&gt;Yes, basic problem.&amp;nbsp; You are mixing macro code and datastep code.&amp;nbsp; Macro is a find replace system which expands your text&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;/U&gt; the datastep code is compiled and run.&amp;nbsp; Start your question by providing test data in the form of a datastep and what you want to see out.&amp;nbsp; Also post any code - full working not a snippet - so that we can see what you are doing.&amp;nbsp; Otherwise all we can say is what the log says:&lt;/P&gt;
&lt;PRE&gt;ERROR: There is no matching %IF statement for the %ELSE.&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417077#M102431</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-29T15:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: issue with %if %then %else %if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417078#M102432</link>
      <description>&lt;P&gt;Just in terms of syntax, each %DO requires a matching %END.&amp;nbsp; So the first %END matches up with the first %DO J=1 %TO ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not match up with the %IF %THEN statement.&amp;nbsp; So %IF %THEN is not yet ended by the time %ELSE appears.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;makes a valid point.&amp;nbsp; This should be mostly a DATA step application, along the lines of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array myvars {*} &amp;amp;suppvar_list;&lt;/P&gt;
&lt;P&gt;do _n_=1 to dim(myvars);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; QNAM= or whatever it is that you want to do;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417078#M102432</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-29T15:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: issue with %if %then %else %if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417080#M102433</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;PRE&gt;%let suppvar_list=;

 %if &amp;amp;suppvar_list. ne %then %do;
       %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list.));
%end;&lt;/PRE&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AM i doing anything wrong&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have two %do commands but only one %end; You need two %end commands. Same for the next block of code which begins with %else&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417080#M102433</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-29T15:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: issue with %if %then %else %if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417093#M102438</link>
      <description>&lt;P&gt;Proper visual formatting of the code will make your problem obvious, just line up the corresponding %do's and %end's:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%if &amp;amp;suppvar_list. ne
%then %do;
  %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list.));
  %end;
%else %do;
  %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list,%str()));
  %end;  
  %let curr_var = %scan(&amp;amp;suppvar_list., &amp;amp;j.);
    if not missing(&amp;amp;curr_var.)
    then do;
      QNAM = upcase(vname(&amp;amp;curr_var.));
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can now see that the %then %do is missing it's %end&lt;/P&gt;
&lt;P&gt;The data step if then do also misses an end.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417093#M102438</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-29T15:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: issue with %if %then %else %if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417169#M102466</link>
      <description>&lt;P&gt;Make sure you have %END statements for your %DO statements. Same for your DO and END statement in the SAS code your macrro is generating.&lt;/P&gt;
&lt;P&gt;Consistent indentation helps.&amp;nbsp; I like the treat the nesting of macro code and generated SAS code separate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let suppvar_list=;
%if &amp;amp;suppvar_list. ne %then %do;
  %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list.));
    &lt;FONT color="#FF0000"&gt;%* WHAT GOES HERE ? ;&lt;/FONT&gt;
  %end;
&lt;FONT color="#FF0000"&gt;%end;&lt;/FONT&gt;
%else %do;
  %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list,%str()));
    &lt;FONT color="#FF0000"&gt;%* WHAT GOES HERE ? ;&lt;/FONT&gt;
  %end;  
  %let curr_var = %scan(&amp;amp;suppvar_list., &amp;amp;j.);
if not missing(&amp;amp;curr_var.) then do;
  QNAM = upcase(vname(&amp;amp;curr_var.));
&lt;FONT color="#FF0000"&gt;end;&lt;/FONT&gt;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You probably want something more like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let suppvar_list=;
%if &amp;amp;suppvar_list. ne %then %do j = 1 %to %sysfunc(countw(&amp;amp;suppvar_list.));
  %let curr_var = %scan(&amp;amp;suppvar_list., &amp;amp;j.);
if not missing(&amp;amp;curr_var.) then QNAM = upcase(vname(&amp;amp;curr_var.)) ;
%end;
%else %do;
QNAM=' ';
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;So if you pass in a list of two variables you generate this SAS code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not missing(VAR1) then QNAM = upcase(vname(VAR1)) ;
if not missing(VAR2) then QNAM = upcase(vname(VAR2)) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So it looks like you want to set QNAM to the name of the last variable that had a non-missing value.&lt;/P&gt;
&lt;P&gt;Not sure what the UPCASE(VNAME()) is doing, but perhaps the values in your original macro variables are array references?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 18:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-with-if-then-else-if/m-p/417169#M102466</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-29T18:07:14Z</dc:date>
    </item>
  </channel>
</rss>

