title: Calling different call execute on if condition - SAS
body: <p>My intent is to build a dataset in a two step process based on 'frame' dataset using call execute. I need 'a_dataset'. It doesn't exist.
  I read the row of 'frame' dataset:
  in the first row since 'a_dataset' doesn't exist i do macro nexds.
  Second row of 'frame' , i check if 'a_dataset' exist, i found it and i do macro exds.</p>
  <p>Unfortunately my code is not working. For each row in 'frame' the condition of existence is always false and it runs two times the nexds macro.</p>
  <pre><code>
  DATA WORK.frame;
      INFILE DATALINES4
          /*DLM='7F'x*/
          DLM=' '
          MISSOVER
          DSD ;
      INPUT
          from     : $CHAR25.
          tojoin   : $CHAR7. ;
  DATALINES4;
  dataset join1
  dataset join2
  ;;;;
  
  proc delete data=a_dataset;run;
  
  %macro exds(dsn,varname);
  data &amp;dsn.;
  set &amp;dsn.;
  &amp;varname. = 'exist';
  run;
  %mend;
  
  %macro nexds(dsn,varname);
  data &amp;dsn.;
  &amp;varname. = 'notexist';
  run;
  %mend;
  
  
  data _null_;
  
  set frame;
  
  name = strip(tojoin);
  dsname = cat('a_',strip(from));
  
  if ~exist(dsname) then put 'notexist';
  else put 'exist';
  
  if ~exist(dsname) then call execute('%nexds('||dsname||','||name||')');
  else call execute('%exds('||dsname||','||name||')');
  
  run;
  </code></pre>
  <p>It runs this two lines of code:</p>
  <pre><code>1         + data a_dataset; join1 = 'notexist'; run;
  2         + data a_dataset; join2 = 'notexist'; run;
  
  </code></pre>
  <p>instead i want:</p>
  <pre><code>1         + data a_dataset; join1 = 'notexist'; run;
  2         + data a_dataset; set a_dataset; join2 = 'exist'; run;
  </code></pre>
  <p>in the log at the put call  :</p>
  <pre><code>notexist
  notexist
  </code></pre>
  <p>it seems like the if condition is checked at the beginning for each row of 'frame' and not after each it read a single row of 'frame'.</p>