Troubleshooting a web file upload


Functionality to upload files onto the SAS server (from 9.2 on) is available using stored processes and an html input type="file". I introduced this topic last year in my blog post using the SAS Stored Process Developer Guide sample. Of course, it is never as easy as the sample is it? Over the past year I have used this functionality several times and believe me I have had my share of troubleshooting these implementations. So if you are still considering using custom forms with web file uploads, here is a list of items to consider during development.

  1. Access to PIPE
  2. One of the requests was to not just use the file for some processing, but to store the actual file on the physical server. My first attempt was to use the filename PIPE functionality. Such as within UNIX, we would use the copy command cp to move a file from the source location (contained in the the automatic macro variable &_WEBIN_FILEREF) to the new location /uploadfiles and maintain the original file name (using the other macro variable &_WEBIN_FILENAME).

    filename trans PIPE "cp &_WEBIN_FILEREF /uploadfiles/&_WEBIN_FILENAME";
    data _null_;
    infile trans;

    However this requires access to pipe. By default, this functionality is disabled because with this type of access you can conceivably run commands that can delete or wreak other unimaginable havoc on a machine that is not locked down appropriately on the physical side.

    The access to pipe error message looks like this:
    ERROR: Insufficient authorization to access PIPE.
    ERROR: Error in the FILENAME statement.

    Besides enabling access, which in some situations requires an act of congress, there is another way to copy the file from your temporary web location onto the server. Use the RC = function RENAME to move the file over. (Another good reason to keep an eye out for Tips of the Day.)

    data _null_;
    rc = rename(strip(location), strip(filename),'file');

  3. File level security
  4. Once you have the rename function setup (or access to pipe enabled), there is still a small issue around file level security. If the physical folder is locked down, no one can write to it. So what level of security is required? Since this functionality is only available to the stored process server the SASSRV account must have write access to the location.

    The tricky thing is that no errors will be produced for the user in the SAS Stored Process window with the RENAME function, its just no file will be written into the target folder location (in this case c:\uploadfiles). So just grant sassrv RW (read and write) access to the folder structure and retest.

  5. Don't use empty files (0 KB)
  6. One final issue was that during my testing, I was using an empty text file on my desktop. It had a name but 0 content. And guess what? It just doesn't work. Of course, I thought it was my custom form or something with the stored process. But after finally trying another file, I realized that when the file is just empty the &_WEBIN_FILENAME and &_WEBIN_FILEREF macros are not generated.

Have any of you started using the file upload capabilities in stored processes? Any other tips & tricks out there?


About Author

Angela Hall

Senior Technical Architect

Angela offers tips on using the SAS Business Intelligence solutions. She manages a team of SAS Fraud Framework implementers within the SAS Solutions On-Demand organization. Angela also has co-written two books, 'Building BI using SAS, Content Development Examples' & 'The 50 Keys to Learning SAS Stored Processes'.

Related Posts


  1. I've tried this a few different ways (as opposed to reading in a file as binary, and then writing it to the new location) and I continue to get a RC value of 1. I tried hard-coding a file on my SAS server and it works, but once I go back to this format (pulling from temp location to store it somewhere else) I get rc=1.

    Is there any way to troubleshoot this further to see why its not working?

    • Angela Hall
      Angela Hall on

      Hi Ben,
      I have had issues with web forms before. One simple > sign off and it all goes haywire.
      Therefore I would recommend testing the form html code itself.

      Another option is to include %put statements to output more information to the log file.
      It might just be that your copy command has an incorrect path.
      ~ Angela

  2. If i am storing the file
    in Server location D:uploadedsample.wmv -- video file or text file.

    using Hyperlink anchor tag can i get it . Can you please suggest what method to approach. my requirment is using hyperlink need to access store files in server drive using STORE PROCESS.


  3. Hi Angela,

    Right now i am looking for same kind of requirment for one of customer .I have some doudts like
    when we are uploading file (Any format) from local computer to SAS server /other sytem location.
    if /uploadfiles/&_WEBIN_FILENAME" is other system(server) location is we need to give complete path example : in server i want to store are D: drive in specific folder how i need to proceed and also it will helpfull if you explain about how to download same file to local computer


    • Angela Hall

      Zeelan -

      The rc=rename step will copy any file format from the upload process onto a physical folder that is available to the SAS server.

      Here are some additional comments around that data step:
      /*#1 Pathname function generates the server location for the temporary file you just uploaded into the system. Such as c:sas temporary filestn20482word_doc_uploaded.docx*/
      /*#2 the next line generates a full path to where you would like to store the file on the server. in your case change c:uploadfiles to d:path_wherever*/
      /*#3 rc= using a rename function this takes the file located in the full path (generated in #1 above) and moves the file into the physical path on the server (derived in #2 above).*/
      rc = rename(strip(location), strip(filename),'file');
      Hope this helps!

      • Angela,
        Thanks for quick replay.This will certainly help me out
        My requirement is i need to create a HTML page in one store process from where i need to give option to user where he can upload file from his local system and after submit STORE Process it will call one one stp and which should upload this selected file to SAS server i think in second store process above suggested code will work .

        One more request did you have any idea about download file logic using stored process using HTML FORM.


Back to Top