Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
ms_getfile.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Gets a file from SASjs Drive
4 @details Fetches a file on SASjs Drive and stores it in the output fileref.
5
6 Example:
7
8 %ms_getfile(/Public/app/dc/services/public/settings.sas, outref=myfile)
9
10 @param [in] driveloc The full path to the file in SASjs Drive
11 @param [out] outref= (msgetfil) The fileref to contain the file.
12 @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
13
14 <h4> SAS Macros </h4>
15 @li mf_getuniquefileref.sas
16 @li mf_getuniquename.sas
17
18**/
19
20%macro ms_getfile(driveloc
21 ,outref=msgetfil
22 ,mdebug=0
23 );
24
25/* use the recfm in a separate fileref to avoid issues with subsequent reads */
26%local binaryfref floc headref;
27%let binaryfref=%mf_getuniquefileref();
28%let headref=%mf_getuniquefileref();
29%let floc=%sysfunc(pathname(work))/%mf_getuniquename().txt;
30filename &outref "&floc" lrecl=32767;
31filename &binaryfref "&floc" recfm=n;
32
33data _null_;
34 file &headref lrecl=1000;
35 infile "&_sasjs_tokenfile" lrecl=1000;
36 input;
37 put _infile_;
38run;
39
40proc http method='GET' out=&binaryfref headerin=&headref
41 url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
42%if &mdebug=1 %then %do;
43 debug level=2;
44%end;
45run;
46
47filename &binaryfref clear;
48filename &headref clear;
49
50%mend ms_getfile;