Dear All,
I was trying to create a stored process which would upload a csv file from the users computer and create a sas DATAset.
The code i am trying was put together using references given below
Dynamic Parameters for Stored Process
The below code would first execute a stored process which would webout an html custom input form where the user can browse to the location where his csv file is present. On clicking the OK button on the Html the same stored process is executed again but with the parameters that the html sends to the STP which would import the data from the CSV and print the first 10 rows.
On executing the STP the HTML form does get generated correctly but the import doesnot happen.
In the refrence notes it was mentioned that the STP would generate the _webin_ macro variables. But when i execute this code no values get generated for the &_WEBIN_FILEREF. And the import code throws the following error ERROR: Unable to import, please specify a DATAFILE.
Is there something wrong in what i am trying to achieve here. Please do guide.
%macro main;
%global reqtype;
%macro first_request;
data _null_;
file _webout;
PUT '<form action=http://myserver:8080/SASStoredProcess/do method="post" enctype="multipart
/form-data">';
PUT '<input type="hidden" name="_PROGRAM" value="/PATH/STP_NAME">';
PUT '<input type="hidden" name=reqtype value="report">';
PUT '<table border="0" cellpadding="5">';
PUT '<tr>';
PUT '<th>Choose a file to upload:</th>';
PUT '<td><input type="file" name="myfile"></td>';
PUT '</tr>';
PUT '<tr>';
PUT '<td colspan="2" align="center"><input type="submit" value="OK"></td>';
PUT '</tr>';
PUT '</table>';
PUT '</form>';
RUN;
%mend first_request;
%macro report;
%let CSVFILE=%sysfunc(pathname(&_WEBIN_FILEREF));
proc import datafile="&CSVFILE"
out=work.mydata
dbms=csv
replace;
getnames=yes;
run;
%stpbegin;
title 'First 10 records of CSV file after importing to a SAS table.';
proc print data=work.mydata(obs=10); run; quit;
%stpend;
%mend report;
%if "&reqtype" = "report" %then %do;
%report;
%end;
%else %do;
%first_request;
%end;
%mend main;
%main;
Hi NN
See this sample code below.
This works for me, it will display information about the uploaded file (Macrovars starting with _WEBIN).
Hi NN
See this sample code below.
This works for me, it will display information about the uploaded file (Macrovars starting with _WEBIN).
Thanks a lot... This works well
Hi Bruno,
Your program looks good...! I just tried to execute this program in my environment.
Initially I faced few errors but I managed to correct it.
After correcting the error, the input form appears. When I select the employee.csv file and click "OK" The following message appears
SAS Stored Process Web Application
Welcome to the version 9 SAS Stored Process Web Application. This application allows you to execute stored process from a web browser.
It didn't produce the proc print output that I was expecting. This is the first time I am trying stored process web application so please advise what I should do to get the output.
Dhana
Some questions:
Which SAS Version are you using
Did you create the Stored Process through Enterprise Guide (make sure the SAS code does not contain any %STPBEGIN and %STPEND)
Did you have a look at the Stored Process Server log for any indications what could be wrong
Bruno,
I am using SAS 9.1.3. Yes, I created Stored Process through Enterprise Guide, but I removed the %STPBEGIN and %STPEND macro calls.
When I was executing the stored process, I checked the option " Show SAS Log? Yes ". It generated the log, in that also I don't see any error messages.
Please advise does it require any settings/configuration some where.
Thanks
Dhana
The ability to upload files through a Stored Process was added with SAS9.2, see also
http://support.sas.com/documentation/cdl/en/stpug/61271/HTML/default/viewer.htm#stpugwhatsnew902.htm
Thanks Bruno. I will check this link and If I need any help I will come back to you.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.