diff --git a/all.sas b/all.sas index 6f17814..036b596 100644 --- a/all.sas +++ b/all.sas @@ -18854,6 +18854,38 @@ run; ) %mend ms_createfile; +/** + @file + @brief Gets a file from SASjs Drive + @details Fetches a file on SASjs Drive and stores it in the output fileref. + + Example: + + %ms_getfile(/some/stored/file.ext, outref=myfile) + + @param [in] driveloc The full path to the file in SASjs Drive + @param [out] outref= (msgetfil) The fileref to contain the file. + @param [in] mdebug= (0) Set to 1 to enable DEBUG messages + + +**/ + +%macro ms_getfile(driveloc + ,outref=msgetfil + ,mdebug=0 + ); + +filename &outref temp; + +proc http method='GET' out=&outref + url="&_sasjs_apiserverurl/SASjsApi/drive/file?filePath=&driveloc"; +%if &mdebug=1 %then %do; + debug level=2; +%end; +run; + + +%mend ms_getfile; /** @file @brief Executes a SASjs Server Stored Program diff --git a/server/ms_getfile.sas b/server/ms_getfile.sas new file mode 100644 index 0000000..8041641 --- /dev/null +++ b/server/ms_getfile.sas @@ -0,0 +1,32 @@ +/** + @file + @brief Gets a file from SASjs Drive + @details Fetches a file on SASjs Drive and stores it in the output fileref. + + Example: + + %ms_getfile(/some/stored/file.ext, outref=myfile) + + @param [in] driveloc The full path to the file in SASjs Drive + @param [out] outref= (msgetfil) The fileref to contain the file. + @param [in] mdebug= (0) Set to 1 to enable DEBUG messages + + +**/ + +%macro ms_getfile(driveloc + ,outref=msgetfil + ,mdebug=0 + ); + +filename &outref temp; + +proc http method='GET' out=&outref + url="&_sasjs_apiserverurl/SASjsApi/drive/file?filePath=&driveloc"; +%if &mdebug=1 %then %do; + debug level=2; +%end; +run; + + +%mend ms_getfile; diff --git a/tests/serveronly/ms_getfile.test.sas b/tests/serveronly/ms_getfile.test.sas new file mode 100644 index 0000000..a32ceab --- /dev/null +++ b/tests/serveronly/ms_getfile.test.sas @@ -0,0 +1,45 @@ +/** + @file + @brief Testing ms_getfile.sas macro + +

SAS Macros

+ @li ms_createfile.sas + @li ms_getfile.sas + @li mp_assert.sas + @li mp_assertscope.sas + +**/ + + +/* first make a remote file */ +filename stpcode temp; +%let fname=%mf_getuniquename(); +data _null_; + file stpcode; + put "data &fname;run;"; +run; +%ms_createfile(/sasjs/tests/&fname..sas + ,inref=stpcode + ,mdebug=1 +) + +%mp_assertscope(SNAPSHOT) +%ms_getfile(/sasjs/tests/&fname..sas,outref=testref) +%mp_assertscope(COMPARE) + +%let test1=0; +data _null_; + infile testref; + input; + call symputx('test1',_infile_); +run; + +%mp_assert( + iftrue=("&test1"="data &fname;run;"), + desc=Checking file was created with the same content, + outds=work.test_results +) + + + +