Sample 26164: Macro Tool to Include External HTML Using SAS/IntrNet
Including external HTML is another sample macro tool. Using a macro, instead of copying the DATA step shown above into every program that uses this technique, is not only simpler, it is also more easily maintained. A sample macro tool, externalHTML, is included in the sample environment for this book. It has two parameters:
- SOURCE
Gives the name or location of the external HTML or both.
- TYPE
Defines how to interpret the value of the SOURCE parameter:
- Fileref: the value of SOURCE is an existing SAS filename.
- Catalog: the value of SOURCE is a four-level SAS catalog source entry name.
- Any other value, including blank, implies that the value of SOURCE is the path to or the name of an operating system file.
The code for the externalHTML macro is included in the sample environment and is substantially the same as the code that appears above. The primary difference is that the macro does not use the special variable _infile _. Instead, it uses a DATA step variable, which can include up to 32,755 characters. Using a DATA step variable allows any single line in the template file to expand (after macro variable resolution and macro execution) to this length.
Here is the complete program for this example:
Note: This is a generic tool that can be used to page through any SAS data set. It will be expanded upon in the next section.
-
%setDefaultValue(firstobs,1)
%setDefaultValue(atATime,5)
%setDefaultValue(data,sashelp.class)
%let obs = %sysfunc(max(&firstobs + &atATime - 1,1));
%let previous = %sysfunc(max(%eval(&firstobs - &atATime),1));
%let next = %eval(&firstobs + &atATime);
data _null_;
/* this step is used to just make sure the maximum obs is not exceeded */
if 0 then set &data nobs=nobs;
call symput('datasetObs',compress(put(nobs,8.)));
obs = min(&obs,nobs);
call symput('Obs',compress(put(obs,8.)));
stop;
run;
ods listing close; /* no listing output*/
ods html file = _webout ((title="Using a Macro Tool to include Externally Defined HTML" no_ bottom _matter) style = sasweb;
proc print data=&data(firstobs=&firstobs obs=&obs);
title "Observations &firstobs-&obs of &data";
run;
ods html close;
%externalHTML
(type=catalog,
source=saspress.template7.external_HTML_Macro.source
)
%externalHTML
(type=catalog,
source=saspress.template7.trailer_Content.source
)
The externalHTML macro is called twice since the HTML that represents the form controls is
applicable only to this program, while the other entry might be used more broadly. Such
externally defined HTML should be partitioned to maximize its re-use.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Including external HTML is a sample macro tool. Using a macro, instead of copying the DATA step shown above into every program that uses this technique, is not only simpler, it is also more easily maintained. This tip submitted by Don Henderson.
Type: | Sample |
Topic: | Internal Administration ==> BBU
|
Date Modified: | 2007-05-30 03:02:51 |
Date Created: | 2007-05-30 03:02:51 |
Operating System and Release Information
SAS System | SAS/IntrNet | All | 8 TS M0 | n/a |