A useful feature of SAS Stored Processes is the ability to load multiple files in a single request. This could be a bunch of CSVs for processing, or even a `.sas` program that you want to `%include` along with some associated data (deliberate SAS injection). This is particularly useful when you are running a build process, eg for a web application, and you need to send across some SAS programs that should be compiled into Stored Processes and re-downloaded as a distributable SPK. If you send your executable .sas program as the first file, to a ‘master’ STP that has just one line of code (`%inc &_webin_fileref1/source2;`), then this becomes the only entry point you need when running from a non-SAS environment!
Anyway, here is the sample code:
curl -v -L -b cookiefile -c cookiefile \ -H "Content-Type: multipart/form-data" \ -F "[email protected]/runme.sas" \ -F "[email protected]/processme.csv" \ -F "[email protected]/processmeaswell.csv" \ "$SERVER?_program=$STP&_username=$USER&_password=$PASS" --output "/tmp/out.txt"
Things to note:
- -v = verbose
- -L = follow the redirects
- -b / -c = cookie in / out
- -H = http header
- -F = Files for upload
- –output = output filename
- $SERVER = your SAS server, eg: https://yourserver.com/SASStoredProcess/do
- $STP = full metadata path to STP, eg: /my/meta/path/to/my/service
- $USER = sas username, including @saspw suffix if an internal account
- $PASS = sas password
The following automatically assigned macro variables will be helpful when accessing the files you have uploaded:
- _WEBIN_FILE_COUNT – contains a count of the number of files that were uploaded
- _WEBIN_FILEREF – a unique fileref that can be used to access the file
- _WEBIN_FILENAME – the location in which the file is saved in SAS (eg in WORK)
- _WEBIN_NAME – the name given for the file on upload (eg somefile1 / somefile2 in the example)
The above variables are actually macro variable arrays – so _WEBIN_FILENAME1 will be the first, _WEBIN_FILENAME2 will be the second, and so on.
If you want more background on building web applications with SAS, check out the following resources!
- Build Lightning Fast Web Apps with SAS
- H54S – HTML5 data adapter for SAS
- 5 tips for SAS App Developers
The following web apps are available from Boemska as open source projects:
Finally, if you are looking to optimise your web applications for maximum performance then be sure to check out Boemska ESM.