SAS author's tip: The problem with generating valid HTML


This week's SAS tip is from Don Henderson and his book Building Web Applications with SAS/IntrNet. A SAS user since 1975, Don was one of the original developers for the SAS/IntrNet Application Dispatcher.

The following excerpt is from SAS Press author Don Henderson and his book "Building Web Applications with SAS/IntrNet: A Guide to the Application Dispatcher" Copyright © 2007, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software).

7.1.1  The Problem with Generating Valid HTML

Generating valid HTML can be complicated by the fact that both SAS and HTML require strings to be quoted. For HTML, the double quote (“) character is used. For SAS, either a single (‘) or double quote (“) can be used. In addition, SAS uses the ampersand (&) as a trigger to indicate that the next word or token should be interpreted as a macro variable reference. However, in HTML, the & is interpreted as the separator character for name/value pairs in links and as the indicator for HTML character entities (e.g.,   - a non-breakable space). For example, the following HTML string invokes the Application Dispatcher to execute a program and pass the values A and B as the values for parameters one and two:


When SAS sees this string, depending on how the values are quoted, SAS might attempt to resolve &one and &two as macro variable references instead of allowing the &s to remain as the HTML separator characters. In these cases, SAS does not produce the desired results. The solution is to use single quotes. However, there are typically cases where the desired values for name/value pairs are macro variable references, e.g., if the generated URL is to include the value of _debug. The value of _debug to be used is the value of the macro variable reference &_debug.

In the following URL string, the second reference to &_debug is to a macro variable reference, while the first one should be treated as a character literal:


In this case, &_url should be resolved, and the first &_debug reference is to be taken literally: the generated text should be the text &_debug. However, the second reference should be resolved by the macro processor. The first reference must be single quoted in SAS to prevent macro resolution, while the second reference must be double quoted to allow resolution. These two are in conflict.

Now consider another type of HMTL string for a FORM tag field in the following example.

<INPUT TYPE="hidden" NAME="_debug" VALUE="some value">

Here we want some value to resolve from the macro variable reference &_debug. This would mandate that we use double quotes to quote this string; yet this is at conflict with the requirement that the quoted string include embedded double quotes.

The following sections introduce techniques to address these issues. Although the examples have been coded to illustrate the various techniques, you should adopt a consistent approach when implementing an application; i.e., use a single technique consistently.

Visit Don's author page to learn more about his work, including his upcoming new book SAS Server Pages: Generating Dynamic Content--and to view free book content.



About Author

Shelly Goodin

Social Media Specialist, SAS Publications

Shelly Goodin is SAS Publications' social media marketer and the editor of "SAS Publishing News". She’s worked in the publishing industry for over thirteen years, including seven years at SAS, and enjoys creating opportunities for fans of SAS and JMP software to get to know SAS Publications' many offerings and authors.

Comments are closed.

Back to Top