You can
use the SAS Stored Process Web Application to upload one or more files to
your SAS Stored Process Server. The upload process is initiated by a custom
input form that contains an INPUT tag with the attribute TYPE set to file:

<input type="file" name="myfile">

This tag enables you to specify the file that you want to upload. For
more information, see Specifying Custom Input Forms.
After the form data is submitted, the file you chose and any other name/value
pairs that are contained in the custom input form are sent to the stored process
server. Your stored process can then use both the name/value pairs and the
file that was uploaded.

The
reserved SAS macro variables that are associated with uploading files all
start with _WEBIN_.

_WEBIN_CONTENT_LENGTH

specifies the length, in bytes, of the file that was uploaded.

_WEBIN_CONTENT_TYPE

specifies the content type that is associated with the file.

_WEBIN_FILE_COUNT

specifies the number of files that were uploaded. If no
files were uploaded, then the value of this variable will be set to zero.

_WEBIN_FILEEXT

specifies the extension of the file that was uploaded.

_WEBIN_FILENAME

specifies the original location of the file.

_WEBIN_FILEREF

specifies the SAS fileref that is automatically assigned
to the uploaded file. You can use this fileref to access the file. The uploaded
file is stored in a temporary location on the stored process server, and will
be deleted when the request is completed. Be sure to copy the file to a permanent
location if you need to access it at a later date.

_WEBIN_NAME

specifies the value that is specified in the NAME attribute
of the INPUT tag.

_WEBIN_SASNAME

specifies a unique name for the SAS table, view, or catalog
that was uploaded. A value is set for this macro variable only if a SAS table,
view, or catalog was uploaded. All SAS data types are stored in the Work library.
The type of SAS file that was uploaded is stored in the _WEBIN_SASTYPE macro
variable. See also _WEBIN_SASNAME_ORI.

_WEBIN_SASNAME_ORI

specifies the original name of the SAS table, view, or catalog
that was uploaded. If a SAS table named mydata.sas7bdat
was uploaded, then _WEBIN_SASNAME_ORI contains the value mydata. A value is set for this macro variable only if a SAS table,
view, or catalog that was uploaded. All SAS data types are stored in the Work
library. The type of SAS file that was uploaded is stored in the _WEBIN_SASTYPE
macro variable. See also _WEBIN_SASNAME.

_WEBIN_SASTYPE

specifies the type of SAS file that was uploaded: DATA for
SAS tables, VIEW for SAS views, and CATALOG for SAS catalogs. A value is set
for this macro variable only if a SAS table, view, or catalog was uploaded.
The name of the uploaded file is stored in the _WEBIN_SASNAME macro variable.

_WEBIN_STREAM

specifies the name of the data source that was used to upload
the file.

_WEBIN_STREAM_COUNT

specifies the number of files that were uploaded. If no
files were uploaded, then the value of this variable will be set to zero.

If you are uploading more than one file, then unique macro variables
will be created for each file. This applies to all of the previous reserved
macro variables except _WEBIN_FILE_COUNT and _WEBIN_STREAM_COUNT.

Note: For z/OS, the SAS server must be invoked with the FILESYSTEM=HFS
option in order to be able to upload SAS file types.

In the preceding HTML example, you must replace "StoredProcessWebApplicationURL" with the path to the SAS Stored Process Web Application.
This path is usually http://YourServer:8080/SASStoredProcess/do
,
where YourServer corresponds to the domain name
of your stored process server. Similarly, you need to specify the path and
name of the stored process that you want to execute after the file has been
uploaded. You should specify the exact values that are shown for the METHOD
and ENCTYPE attributes of the FORM tag.

The INPUT tag in the preceding HTML example is used to create the Browse button and text entry field in the preceding
figure.
The appearance of this control might be different depending on which Web browser
you use, but the functionality should be the same. Clicking the Browse button enables you to navigate to the file that you want
to upload. You can choose any file that you have access to. This example uses
the file readme.txt, which resides in the Windows
directory C:\temp.

After you select a file and click OK, all
form data is sent to the SAS Stored Process Web Application, which forwards
the data to the stored process server. As a result, the following SAS macro
variables are created:

Specifies the size of the file that was uploaded in bytes (supplied
automatically by the Web browser).

_WEBIN_CONTENT_TYPE

text/plain

Specifies the content type that corresponds to the file that was uploaded
(supplied automatically by the Web browser).

_WEBIN_FILE_COUNT

1

Specifies the number of files that were uploaded.

_WEBIN_FILEEXT

txt

Specifies the extension of the file that was uploaded.

_WEBIN_FILENAME

C:\temp\README.txt

Specifies the name and original location of the file that was uploaded.

_WEBIN_FILEREF

#LN00197

Specifies the SAS fileref that you can use to access the uploaded file.
This fileref is assigned for you by the SAS server.

_WEBIN_NAME

myfile

Specifies the value that corresponds to the NAME attribute of the INPUT
tag.

Your stored process has access to the uploaded file through the fileref
that is stored in the value of the _WEBIN_FILEREF macro variable. The following
code example returns the uploaded file to the client:

The preceding code example shows how to use the _WEBIN_CONTENT_TYPE
macro variable to set the content-type header. This code also shows how to
use the _WEBIN_FILEREF macro variable to access the uploaded file.

Example 2 uses the files readme.txt and winter.jpg, which reside in the Windows directory
C:\temp. Note that the two input files do not need to be in
the same directory.

After you select a file and click OK, all
form data is sent to the SAS Stored Process Web Application, which forwards
the data to the stored process server. As a result, the following SAS macro
variables are created:

Because the IMPORT procedure requires a full path to the CSV file, you
must first use the PATHNAME function to get the path to the file. The GETNAMES
statement uses the data in the first row of the CSV file for the SAS column
names. For more information, see the IMPORT procedure in the
Base SAS Procedures Guide.

An alternative method is to write a DATA step to import the CSV file.
This method requires only Base SAS. The following code is an example of how
to do this:

Starting with Excel XP (Excel 2002), a workbook can be saved
as an XML file. This XML file can be read into SAS using the SAS XML LIBNAME
engine and an XMLMap. Each worksheet in the workbook will be imported to a
SAS table with the same name. The column headings in the worksheets will be
used for the column names in the SAS tables. The following code is an example
of how to do this. Be sure to include the appropriate directory paths.

The %INCLUDE statement makes the XLXP2SAS macro available to SAS. The
%XLXP2SAS macro imports the data from all the worksheets into separate SAS
tables with the help of an XMLMap. For more information, see the paper "Creating
AND Importing Multi-Sheet Excel Workbooks the Easy Way with SAS" at http://support.sas.com/rnd/papers. Links
are available for you to download both the macro and the XMLMap.

When a SAS data
type (table, view, or catalog) has been uploaded, additional reserved macro
variables are created. For example, the following macro variables will be
created if the file C:\temp\djia.sas7bdat has
been uploaded:

Because the IMPORT procedure requires a full path to the Excel workbook,
you must first use the PATHNAME function to get the path to the file. The
GETNAMES statement uses the data in the first row of the workbook for the
SAS column names. For more information, see the IMPORT procedure in the
Base SAS Procedures Guide.