title: SAS: put format in macro
body: <p>I am trying to create a new variable by assigning a format to an existing variable. I'm doing this from within a macro. I'm getting the following error: ": Expecting a format name." Any thoughts on how to resolve? Thanks!</p>
  
  <pre><code>/* macro to loop thru a list of vars and execute a code block on each. This is working     fine. */ 
  %macro iterlist  
  ( 
    code =  
   ,list = 
  ) 
  ;  
    %*** ASSIGN EACH ITEM IN THE LIST TO AN INDEXED MACRO VARIABLE &amp;&amp;ITEM&amp;I ; 
    %let i = 1; 
    %do %while (%cmpres(%scan(&amp;list., &amp;i.)) ne ); 
      %let item&amp;i. = %cmpres(%scan(&amp;list., &amp;i.));  
      %let i = %eval((&amp;i. + 1);  
    %end; 
    %*** STORE THE COUNT OF THE NUMBER OF ITEMS IN A MACRO VARIABLE: &amp;CNTITEM; 
    %let cntitem = %eval((&amp;i. - 1); 
  
    %*** EXPRESS CODE, REPLACING TOKENS WITH ELEMENTS OF THE LIST, IN SEQUENCE; 
    %do i = 1 %to &amp;cntitem.;                                        
      %let codeprp = %qsysfunc(tranwrd(&amp;code.,?,%nrstr(&amp;&amp;item&amp;i..))); 
      %unquote(&amp;codeprp.) 
    %end;  
  %mend  iterlist; 
  
  
  /* set the list of variables to iterate thru  */ 
  %let mylist = v1 v2 v3 v4; 
  
  
   /* create a contents table to look up format info to assign in macro below*/ 
  proc contents data=a.recode1 noprint out=contents; 
  run; 
  
  
  
  
  /* macro to create freq and chisq tables for each var */ 
  
  %macro runfreqs (variabl = );
  proc freq data=a.recode1 noprint ; 
      tables &amp;variabl.*improved /out=&amp;variabl._1 chisq; 
      output out=&amp;variabl.chisq n pchi  ;
  run;  
  
  
  
      /* do some more stuff with the freq tables, then grab format for variable from contents */ 
  data _null_; 
      set contents; 
      if name="&amp;variabl." then CALL SYMPUT("classformat", format); 
  
  run; 
  
  data &amp;variabl._3; 
  length classvalue $ 30 ; 
      set &amp;variabl._2; ; 
  
              /* output a new var using the macro variable for format that we pulled from contents above. Here's where the error occurs.  */ 
      classvalue=put(class, %quote(&amp;classformat.));  
  
  
  run; 
  
  
  
  
  %mend  runfreqs; 
  
  
  * run the macro, iterating thru var list and creating freq tables; 
  %ITERLIST(list = &amp;mylist., code = %nrstr(%runfreqs(variabl = ?);)); 
  </code></pre>