title: Assigning a SAS statement to a macro variable
body: <p>I have a dataset that contains the names and attributes of variables that I want to define for a dataset within a macro.  For example:</p>
  
  <pre><code>variable_name = "filedate"  
  variable_length = 8  
  variable_label = "Date file was loaded"  
  variable_format = "date9."
  variable_derivation = "filedate = today()"
  </code></pre>
  
  <p>The macro does something like this:</p>
  
  <pre><code>%macro create_ds;  
  
      data _null_;
      set variable_definitions;
          call symputx('varname', variable_name);
          call symputx('varlength', variable_length);
          call symputx('varlabel', variable_label);
          call symputx('varformat', variable_format);
          call symputx('varderive', variable_definition);
      run;  
  
      data newds;
          attrib &amp;varname length=&amp;varlength label="&amp;varlabel" format=&amp;varformat;
          &amp;varderive;
      run;
  
  %mend create_ds;
  </code></pre>
  
  <p>What I hoped the datastep would look like is:</p>
  
  <pre><code>data newds;
      attrib filedate length=8 label="Date file was loaded" format=date9.;
      filedate = today();
  run;
  </code></pre>
  
  <p>What I actually get is:</p>
  
  <pre><code>data newds;
      attrib filedate length=8 label="Date file was loaded" format=date9.;
      .;
  run;
  </code></pre>
  
  <p>It then throws an error because "." is not a valid statement.</p>
  
  <p>Is there a way to assign a datastep statement to a macro variable and actually have it execute?</p>