Thursday, September 22, 2022

Download SAS work dataset in Viya 4

In Viya 4 SAS Studio, we can not download directly from SAS libraries but export text file (e.g. comma-delimited, tab-delimited). As you can see, we can upload and download files from Contents. Therefore, we can leverage Viya Files service to download SAS datasets. Below is the sample code.
data result;
	set sashelp.class;
run;

filename out filesrvc folderpath='/Users/xxxxx/My Folder' 
	filename='result.sas7bdat' recfm=n lrecl=32767;
filename in "%sysfunc(pathname(work))/a.sas7bdat" recfm=n lrecl=32767;

data _null_;
    rc = fcopy('in', 'out');
    put rc=;
    length msg $1000;
    msg = sysmsg();
    put msg=;
run;