Contents SAS/IntrNet 9.1: Application Dispatcher Previous Next

Creating Temporary Files

The Dispatcher program creates a temporary file for each request. When multiple requests are run at the same time, one request may write over the temporary file of another. There are several ways to create a unique file for the life of a request so that files do not interfere with each other:

Creating a File with a Unique Name

To create a uniquely named file, use a random function to generate the filename. Then, use the name in a FILENAME statement:

   /* Use a data step function RANUNI to generate a random number 
   and format the number with some text to create the unique name. 
   The RAN macro variable will be something like 'A2578900.txt'  */

   data _null_;
      numb = ceil (ranuni(0)*10000000);
      r = 'A' || put(numb, Z7.) || '.txt';
      call symput ('ran', r);

   filename foo "c:\temp\&ran";  
   /* prepend the temp subdirectory */
   data _null_;
      file foo;
      put 'This is output to a uniquely named file';

This technique requires that you explicitly delete the file when you are finished.

Creating a File in a Unique Subdirectory

You can avoid file interference by using a unique subdirectory. Beginning with Version 8 of SAS/IntrNet: Application Dispatcher, the WORK library is unique for each request. Find the path to the WORK library and use it as the subdirectory to store the temporary file.

Note: To append text to a macro variable reference, use the period (.) operator.

   /* use pathname function to get work library's path and store 
   in macro variable wpath */

   %let wpath=%sysfunc(pathname(work));

   /* use wpath macro variable and append filename to it in 
   filename statement  */

   filename foo "&wpath.\winapi.txt";

   data _null_;
   file foo;
   put 'This output is going to file in the work subdirectory';

If the SESSIONS feature is used, then you can specify the path of the SAVE library:

   %let spath=%sysfunc(pathname(save));
   filename foo "&spath.\winapi.txt";

This technique deletes the file automatically at the end of the request.

Storing a File in a Unique Catalog

You can create a unique file for each request by storing the file in a unique SAS catalog. Text can be easily stored in a catalog SOURCE memtype by using the CATALOG access method.

   filename foo catalog "";
   data _null_;
   file foo;
   put 'This output is going to file in the work catalog';


You can use any one of these techniques in a Dispatcher program to create unique files for each request. To put it all together, here is a Dispatcher program that reports the username for the current process:

   /*           S A S   S A M P L E   L I B R A R Y                 */
   /*                                                               */
   /*     NAME: HelloWorld with a twist                             */
   /*    TITLE: Hello World                                         */
   /*  PRODUCT: SAS/IntrNet (Application Dispatcher)                */
   /*   SYSTEM: ALL                                                 */
   /*     KEYS:                                                     */
   /*    PROCS:                                                     */
   /*     DATA:                                                     */
   /*                                                               */
   /*  SUPPORT: Web Tools Group             UPDATE: 20JAN1999       */
   /*      REF:    */
   /*     MISC:                                                     */

   /* create macro variable containing the path to the work subdirectory  */
   %let wpath=%sysfunc(pathname(work));
   %put &wpath;

   filename sascbtbl "&wpath.\winapi.txt";

   /* write WINAPI GetUserNameA parameter list to the file for later use */

   data _null_;
   file sascbtbl;
   input line $char80.;
   put line $char80.;
   routine GetUserNameA
   arg 1 char update format=$cstr20;
   arg 2 num  update format=pib4.;

   /* Here's the DATA step: Modulen will use the filename sascbtbl for 
   parameter list to the called API  */

   data _null_;
      length Name $20.;
      put rc= Name=;

   /* Store the current process username in the macro named vqpname  */

      call symput('vqpname',name);
   /*simply write out a Web page that says "Hello World!"*/
   /* use a DATA step variable and a macro variable in displayed text  */

   data _null_;

   /* store macro variable value in data set variable named vname  */

      file _webout;
      put '<HTML>';

   /*  Use data set variable in the output   */
      put '<HEAD><TITLE>Hello World!' vname ' is running dispatcher! 
      put '<BODY>';
   /*  Use macro variable in the output   */

      put "<H1>Hello World!  Your work path is &wpath.  
	     vname is &vqpname.</H1>";
      put '</BODY>';
      put '</HTML>';

Contents SAS/IntrNet 9.1: Application Dispatcher Previous Next