Published on :
Reporting CREATION_INTERNE

Generating an interactive HTML page with JavaScript

This code is also available in: Deutsch Español Français
The script is a SAS© Stored Process designed to be executed via a web server. It produces a complete HTML page containing JavaScript code to manage the opening and closing of a pop-up window in response to various user actions (hover, click, double-click). The pop-up window itself attempts to load another Stored Process. Additionally, the script decodes and displays HTTP cookies sent by the client. The whole is encapsulated to function in the SAS© 9 or Viya Stored Processes environment, using the _webout output destination.
Data Analysis

Type : CREATION_INTERNE


The main content (HTML and JavaScript code) is generated directly in the script via a DATA _NULL_ step with inline data (CARDS4 statement). It also uses the '_htcook' environment macro variable to retrieve client cookies, which is an external source provided by the SAS application server.

1 Code Block
DATA STEP
Explanation :
This DATA _NULL_ step uses the special output destination '_webout' to begin generating an HTML page. The HTML and JavaScript code, which is read as inline data via the CARDS4 statement, is written directly to the web output stream. The included JavaScript handles user events (clicks, mouse movements) to open and close a pop-up window.
Copied!
1DATA _null_ ;
2 INPUT ;
3 file _webout ;
4 put _infile_ ;
5cards4 ;_card_content_;
6;;;;
7RUN ;
2 Code Block
DATA STEP
Explanation :
This second DATA _NULL_ step continues to write to the '_webout' output. It adds a title for a cookie section, decodes and displays the content of the Stored Process macro variable '_htcook' (which contains browser cookies), then closes the HTML tags of the page.
Copied!
1DATA _null_ ;
2 file _webout ;
3 put '<h1>Cookies</h1>' ;
4 htcook=htmldecode("&_htcook") ;
5 put htcook ;
6 put '</body>' ;
7 put '</html>' ;
8RUN ;
3 Code Block
Macro
Explanation :
The %STPBEGIN and %STPEND macros are markers used by the SAS Stored Processes framework to delimit the code to be executed. The following line of code is a defensive programming technique to ensure proper termination of macro calls in any context.
Copied!
1%STPBEGIN;
2%STPEND;
3*';*"*/;RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.