Production Ready Macros for SAS Application Developers
mm_createwebservice.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Create a Web Ready Stored Process
4  @details This macro creates a Type 2 Stored Process with the Boemska h54s
5  adapter (development / file upload version) included as pre-code.
6 
7  The adapter code is loaded direct from github, so internet access is a
8  currently a dependency (feel free to submit a PR to provide a fileref
9  based approach).
10 
11  Usage:
12 
13  * compile macros ;
14  filename mc url "https://raw.githubusercontent.com/Boemska/macrocore/master/macrocore.sas";
15  %inc mc;
16 
17  * parmcards lets us write to a text file from open code ;
18  filename ft15f001 "%sysfunc(pathname(work))/somefile.sas";
19  parmcards4;
20  * enter stored process code below ;
21  proc sql;
22  create table outdataset as
23  select * from sashelp.class;
24 
25  * output macros for every dataset to send back ;
26  %bafheader()
27  %bafoutdataset(forJS,work,outdataset)
28  %baffooter()
29  ;;;;
30 
31  * create the stored process ;
32  %mm_createwebservice(service=MyNewSTP
33  ,role=common
34  ,project=/User Folders/sasdemo/myapp
35  ,source=%sysfunc(pathname(work))/somefile.sas
36  )
37 
38 
39  <h4> Dependencies </h4>
40  @li mm_createstp.sas
41  @li mf_getuser.sas
42 
43 
44  @param project= The metadata project directory root
45  @param role= The name of the role (subfolder) within the project
46  @param service= Stored Process name. Avoid spaces - testing has shown that
47  the check to avoid creating multiple STPs in the same folder with the same
48  name does not work when the name contains spaces.
49  @param desc= Service description (optional)
50  @param source= /the/full/path/name.ext of the sas program to load
51  @param precode= /the/full/path/name.ext of any precode to insert.
52  @param adapter= omit this parameter to use the Boemska h54s adapter macros
53  (assumes internet access) else provide the path to a local copy
54  @param server= The server which will run the STP. Server name or uri is fine.
55  @param mDebug= set to 1 to show debug messages in the log
56 
57  @version 9.2
58  @author Allan Bowe
59  @copyright GNU GENERAL PUBLIC LICENSE v3
60 
61 **/
62 
63 %macro mm_createwebservice(
64  project=/User Folders/sasdemo
65  ,role=common
66  ,service=myFirstWebService
67  ,desc=This stp was created automatically by the mm_createwebservice macro
68  ,source=
69  ,precode=
70  ,adapter=h54s
71  ,mDebug=0
72  ,server=SASApp
73 )/*/STORE SOURCE*/;
74 
75 %if &syscc ge 4 %then %do;
76  %put &=syscc;
77  %return;
78 %end;
79 
80 %local mD;
81 %if &mDebug=1 %then %let mD=;
82 %else %let mD=%str(*);
83 %&mD.put Executing mm_createwebservice.sas;
84 %&mD.put _local_;
85 
86 %local work tmpfile;
87 %let work=%sysfunc(pathname(work));
88 %let tmpfile=__mm_createwebservice.temp;
89 
90 /* get adapter code */
91 %if "&adapter"="h54s" %then %do;
92  filename __adaptr url
93  "https://raw.githubusercontent.com/Boemska/h54s/development/sasautos/h54s.sas";
94 %end;
95 %else %do;
96  filename __adaptr "&adapter";
97 %end;
98 
99 data _null_;
100  if _n_=1 then do;
101  put "/* Created on %sysfunc(today(),datetime19.) by %mf_getuser() */";
102  end;
103  file "&work/&tmpfile" lrecl=3000;
104  infile __adaptr end=last;
105  input;
106  put _infile_;
107  if last then put '%bafGetDatasets()';
108 run;
109 filename __adaptr clear;
110 
111 /* add precode if provided */
112 %if %length(&precode)>0 %then %do;
113  data _null_;
114  file "&work/&tmpfile" lrecl=3000 mod;
115  infile "&precode";
116  input;
117  put _infile_;
118  run;
119 %end;
120 
121 /* add the SAS program */
122 data _null_;
123  file "&work/&tmpfile" lrecl=3000 mod;
124  infile "&source";
125  input;
126  put _infile_;
127 run;
128 
129 /* create the project folder if not already there */
130 %mm_createfolder(path=&project)
131 %if &syscc ge 4 %then %return;
132 
133 /* create the role folder if not already there */
134 %mm_createfolder(path=&project/&role)
135 %if &syscc ge 4 %then %return;
136 
137 /* create the web service */
138 %mm_createstp(stpname=&service
139  ,filename=&tmpfile
140  ,directory=&work
141  ,tree=&project/&role
142  ,stpdesc=&desc
143  ,mDebug=&mdebug
144  ,server=&server
145  ,stptype=2)
146 
147 %mend;