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.
To see an example of the features of the multipleNames macro, go to the sample environment located at http://hcsbi.com/IntrNetAppDev/ and select Chapter 7. Then select Using a Macro Tool to include Externally Defined HTML. Other than the text note at the bottom of the page (which is caused by the use of a different external HTML template), the macro produces the same output as shown in Figure 7.8. 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.
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 |