title: SAS Stored Process STP web: How to reference html file for file _webout instead of put statements?
body: <p>So I've seen various pages that inform SAS Stored Process users creating stored process web pages how to do something like:</p>
  
  <p><a href="https://support.sas.com/documentation/cdl/en/stpug/62758/HTML/default/viewer.htm#p0q383asmm4bejn1i7z4q7iv5eke.htm" rel="nofollow noreferrer">https://support.sas.com/documentation/cdl/en/stpug/62758/HTML/default/viewer.htm#p0q383asmm4bejn1i7z4q7iv5eke.htm</a></p>
  
  <pre><code>data _null_;
  file _webout;
  put '&lt;HTML&gt;';
  put '&lt;HEAD&gt;&lt;TITLE&gt;Hello World!&lt;/TITLE&gt;&lt;/HEAD&gt;';
  put '&lt;BODY&gt;';
  put '&lt;H1&gt;Hello World!&lt;/H1&gt;';
  put '&lt;/BODY&gt;';
  put '&lt;/HTML&gt;';
  run;
  </code></pre>
  
  <p>The put HTML statements are nice and a quick way to get HTML to the page, but I'm noticing my HTML using put is getting quite messy and not maintainable.</p>
  
  <p><strong>How can I reference an external HTML file instead?</strong> I do have some SAS macros that I reference in the HTML put statements so I'm not sure if those would resolve in the external html but still interested to see a working example of referencing an external HTML file in a stored process.</p>
  
  <p><strong>UPDATE - My Example Program</strong></p>
  
  <p>In this put HTML I am just writing a form to the web page with some data populated in a drop down. I would just like to call this as raw html from an external HTML file while still resolving the SAS code embedded in the HTML like macro variable references.</p>
  
  <pre><code>%macro test;
  
  proc sql;        
  create table eqmtid_name as        
        select distinct EQMT_ID        
        from library.joined_data;        
  
  %let neqmtid = &amp;sqlobs;        
  quit;        
  
  data _null_;        
  set eqmtid_name;        
   suffix=put(_n_,8.);        
   call symput(cats('EQMTID',suffix), EQMT_ID);        
  run;    
  
  data _null_;
  
  file _webout;
  put '&lt;script type="text/javascript"&gt;document.body.innerHTML = "";&lt;/script&gt;';  
  put '&lt;HTML&gt;';  
  put '&lt;head&gt;';  
  put '&lt;script type="text/javascript"&gt;'; 
  put 'document.addEventListener("DOMContentLoaded", function initialize() {'; 
  put '   var svgs = document.getElementsByTagName("svg");'; 
  put '   for (i = 0; i &lt; svgs.length; ++i) {'; 
  put '    e = svgs[i];'; 
  put '    e.removeAttribute("height");'; 
  put '    e.removeAttribute("width");'; 
  put '    e.setAttribute("width","80%");'; 
  put '   }'; 
  put '   '; 
  put '});'; 
  put '&lt;/script&gt;'; 
  put '&lt;/head&gt;';  
  put '&lt;BODY onload="initialize()"&gt;';   
  put '&lt;HEADER class="pageheader"&gt;'; 
  put '&lt;TABLE&gt;'; 
  put '&lt;tr&gt;';
  put '&lt;td&gt;'; 
  put '&lt;div class="divcenter"&gt;Header Text&lt;/div&gt;'; 
  put '&lt;/td&gt;'; 
  put '&lt;/tr&gt;'; 
  put '&lt;/TABLE&gt;'; 
  put '&lt;/HEADER&gt;'; 
  put '&lt;FORM NAME="sub" METHOD="GET" ACTION="/SASStoredProcess/do"&gt;';            
  put '&lt;INPUT TYPE="HIDDEN" NAME="_program" SIZE="100" VALUE="/Company/IT/Development/APP/stp_program"&gt;';         
  put '&lt;INPUT TYPE="CHECKBOX" NAME="_debug" VALUE="log"&gt;Show SAS Log &lt;br&gt;';       
  put '&lt;TABLE&gt;';        
  put '&lt;tr&gt;';        
  put '&lt;td&gt;';        
  put '&lt;label class="formitem"&gt;Equipment ID:&lt;/label&gt;';        
  put '&lt;/td&gt;';        
  put '&lt;td&gt;';        
  put '&lt;select class="formitem styleinput" name="EQMTID"&gt;' /        
     '&lt;option value=""&gt;&lt;/option&gt;' /        
     %do i = 1 %to &amp;neqmtid; /        
     "&lt;option value = %bquote(")%left(%trim(&amp;&amp;EQMTID&amp;i))%bquote(") &gt;&amp;&amp;EQMTID&amp;i&lt;/option&gt;" /        
     %end; /        
     '&lt;/select&gt;';        
  put '&lt;/td&gt;';        
  put '&lt;/TABLE&gt;';        
  put '&lt;br&gt;'; 
  put '&lt;TABLE&gt;';  
  put '&lt;tr&gt;'; 
  put '&lt;td&gt;'; 
  put '&lt;INPUT class="button" class="formitem" TYPE="SUBMIT" VALUE="Search"&gt;&lt;br&gt;';       
  put '&lt;/td&gt;'; 
  put '&lt;/FORM&gt;'; 
  put '&lt;FORM NAME="download" TARGET="_blank" METHOD="GET" ACTION="/SASStoredProcess/do"&gt;';            
  put '&lt;INPUT TYPE="HIDDEN" NAME="_program" SIZE="100" VALUE="/Company/IT/Development/APP/export_data_stp"&gt;';         
  put '&lt;td&gt;'; 
  put '&lt;INPUT class="button" class="formitem" TYPE="SUBMIT" VALUE="Download"&gt;&lt;br&gt;';       
  put '&lt;/td&gt;'; 
  put '&lt;/FORM&gt;'; 
  put '&lt;/tr&gt;'; 
  put '&lt;/TABLE&gt;'; 
  put '&lt;/BODY&gt;';             
  put '&lt;/HTML&gt;';   
  
  run;
  
  %mend;
  
  %test;
  </code></pre>
  
  <p><strong>UPDATE SOLVED</strong></p>
  
  <p>Thanks to the example Joe outlined below, this is what I had to code to make this work... in SAS Code:</p>
  
  <pre><code>filename htmlfile "/sasdata/IT/APP/file.html";
  
  proc stream outfile=_webout;
  begin
  &amp;streamdelim; %include htmlfile;
  ;;;;
  run;
  </code></pre>
  
  <p>Note: in your html file if you have macro statements like %DO loops, you might get an error like "Error: The %DO statement is not valid in open code". In order to resolve that error I included a macro wrapper in the html file around that statement like this:</p>
  
  <pre><code>&lt;select class="formitem styleinput" name="EQMTID"&gt;       
  &lt;option value=""&gt;&lt;/option&gt;
  
  %macro doeqmt;
  
  %do i = 1 %to &amp;neqmtid;    
  "&lt;option value = %bquote(")%left(%trim(&amp;&amp;EQMTID&amp;i))%bquote(") &gt;&amp;&amp;EQMTID&amp;i&lt;/option&gt;"
  %end;
  
  %mend;
  %doeqmt;
  
  &lt;/select&gt;
  </code></pre>