BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dipand
Quartz | Level 8

Hello to all, my client asks to create a page that can be called up from visual analytics to give the user the possibility to upload excel sheets. At the moment I have created a small job that allows you to select the file:

code:

 

data _null_;
file _webout;
put "<html>";
put "<body>";
put'<form method="post" enctype="multipart/form-data">';
put"<div>";
put '<label for="file">Choose file to upload</label>';
put'<input type="file" id="file" name="file" multiple>';
put"</div>";
put" <div>";
put"<button>Submit</button>";
put" </div>";
put"</form>";
put"</body>";
put "</html>";

 

the problem I have is that I don't know how to save the file in a path of my server to be able to process it with SAS. Can anyone give me directions?

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Stu_SAS
SAS Employee

When files are uploaded to SAS through either a Viya Job or STP, they are saved to a temporary storage location. You can access it using the macro variable _WEBIN_FILEREF. Since they can upload multiple files, multiple macro variables will be available, and the number of files uploaded is stored in _WEBIN_FILE_COUNT. For example, if they are uploading two files:

 

 

_WEBIN_FILE_COUNT = 2
_WEBIN_FILEREF1   = #LN0001
_WEBIN_FILEREF2   = #LN0002

 

However, if _WEBIN_FILE_COUNT = 1, you will only use _WEBIN_FILEREF:

 

_WEBIN_FILE_COUNT = 1
_WEBIN_FILEREF    = #LN0001

If you want to only process these files, count the number of files using _WEBIN_FILE_COUNT, then run your import code just like any other SAS code:

/* Test values */
%let _WEBIN_FILE_COUNT = 1;
%let _WEBIN_FILEREF    = a;
%let _WEBIN_FILEREF1   = b;
%let _WEBIN_FILEREF2   = c;

/* copy:   Optional. if YES, copies the file to "outdir" 
   outdir: Location to copy the uploaded file permanently 
*/
%macro read_uploaded_files(copy=NO, outdir=/directory/here);
    %local i n;
    %let outdir = %superq(outdir);
    %let copy   = %upcase(&copy);

    %put Total files: &_WEBIN_FILE_COUNT;

    /* Read in all the uploaded files and output sequentially to datasets 
named excelout1, excelout2, etc.
*/ %do i = 1 %to &_WEBIN_FILE_COUNT; /* Add a suffix if more than one file was uploaded */ %if(&_WEBIN_FILE_COUNT > 1) %then %let n = &i; %put Importing fileref %nrbquote(&)_WEBIN_FILEREF&n.: &&_WEBIN_FILEREF&n.; /* Read the file in to SAS. Comment out for testing. */ proc import file = &&_WEBIN_FILEREF&n. out = excelout&i. dbms = xlsx replace; run; /* Copy the file somewhere to the server permanently */ %if(&copy. = YES) %then %do; filename outfile "&outdir./&&_WEBIN_FILENAME&n"; %let rc = %sysfunc(fcopy(&&_WEBIN_FILEREF&n., outfile) ); %end; %end; %mend; %read_uploaded_files;

 

 

View solution in original post

1 REPLY 1
Stu_SAS
SAS Employee

When files are uploaded to SAS through either a Viya Job or STP, they are saved to a temporary storage location. You can access it using the macro variable _WEBIN_FILEREF. Since they can upload multiple files, multiple macro variables will be available, and the number of files uploaded is stored in _WEBIN_FILE_COUNT. For example, if they are uploading two files:

 

 

_WEBIN_FILE_COUNT = 2
_WEBIN_FILEREF1   = #LN0001
_WEBIN_FILEREF2   = #LN0002

 

However, if _WEBIN_FILE_COUNT = 1, you will only use _WEBIN_FILEREF:

 

_WEBIN_FILE_COUNT = 1
_WEBIN_FILEREF    = #LN0001

If you want to only process these files, count the number of files using _WEBIN_FILE_COUNT, then run your import code just like any other SAS code:

/* Test values */
%let _WEBIN_FILE_COUNT = 1;
%let _WEBIN_FILEREF    = a;
%let _WEBIN_FILEREF1   = b;
%let _WEBIN_FILEREF2   = c;

/* copy:   Optional. if YES, copies the file to "outdir" 
   outdir: Location to copy the uploaded file permanently 
*/
%macro read_uploaded_files(copy=NO, outdir=/directory/here);
    %local i n;
    %let outdir = %superq(outdir);
    %let copy   = %upcase(&copy);

    %put Total files: &_WEBIN_FILE_COUNT;

    /* Read in all the uploaded files and output sequentially to datasets 
named excelout1, excelout2, etc.
*/ %do i = 1 %to &_WEBIN_FILE_COUNT; /* Add a suffix if more than one file was uploaded */ %if(&_WEBIN_FILE_COUNT > 1) %then %let n = &i; %put Importing fileref %nrbquote(&)_WEBIN_FILEREF&n.: &&_WEBIN_FILEREF&n.; /* Read the file in to SAS. Comment out for testing. */ proc import file = &&_WEBIN_FILEREF&n. out = excelout&i. dbms = xlsx replace; run; /* Copy the file somewhere to the server permanently */ %if(&copy. = YES) %then %do; filename outfile "&outdir./&&_WEBIN_FILENAME&n"; %let rc = %sysfunc(fcopy(&&_WEBIN_FILEREF&n., outfile) ); %end; %end; %mend; %read_uploaded_files;

 

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 426 views
  • 1 like
  • 2 in conversation