Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mx_createjob.sas
Go to the documentation of this file.
1/**
2 @file mx_createjob.sas
3 @brief Create a job in SAS 9, Viya or SASjs
4 @details Creates a Stored Process in SAS 9, a Job Execution Service in SAS
5 Viya, or a Stored Program on SASjs Server - depending on the executing
6 environment.
7
8Usage:
9
10 %* compile macros ;
11 filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
12 %inc mc;
13
14 %* write some code;
15 filename ft15f001 temp;
16 parmcards4;
17 data example1;
18 set sashelp.class;
19 run;
20 ;;;;
21
22 %* create the job;
23 %mx_createjob(path=/Public/app/jobs,name=myjob,replace=YES)
24
25 <h4> SAS Macros </h4>
26 @li mf_getplatform.sas
27 @li mm_createstp.sas
28 @li ms_createfile.sas
29 @li mv_createjob.sas
30
31 @param [in,out] path= The full folder path where the job will be created
32 @param [in,out] name= Job name. Avoid spaces.
33 @param [in] desc= The description of the job (optional)
34 @param [in] precode= Space separated list of filerefs, pointing to the code
35 that needs to be attached to the beginning of the job (optional)
36 @param [in] code= (ft15f001) Space seperated fileref(s) of the actual code to
37 be added
38 @param [in] replace= (YES) Select YES to replace any existing job in that
39 location
40 @param [in] mDebug= (0) set to 1 to show debug messages in the log
41
42 @author Allan Bowe
43
44 <h4> Related Macros </h4>
45 @li mx_createjob.test.sas
46 @li mx_createwebservice.sas
47
48**/
49
50%macro mx_createjob(path=HOME
51 ,name=initJob
52 ,precode=
53 ,code=ft15f001
54 ,desc=This job was created by the mx_createjob macro
55 ,replace=YES
56 ,mdebug=0
57)/*/STORE SOURCE*/;
58
59%if &syscc ge 4 %then %do;
60 %put syscc=&syscc - &sysmacroname will not execute in this state;
61 %return;
62%end;
63
64/* combine precode and code into a single file */
65%local tempref x fref freflist;
66%let tempref=%mf_getuniquefileref();
67%local work tmpfile;
68%let work=%sysfunc(pathname(work));
69%let tmpfile=&tempref..sas;
70filename &tempref "&work/&tmpfile";
71%let freflist=&precode &code ;
72%do x=1 %to %sysfunc(countw(&freflist));
73 %let fref=%scan(&freflist,&x);
74 %put &sysmacroname: adding &fref;
75 data _null_;
76 file &tempref lrecl=3000 termstr=crlf mod;
77 infile &fref lrecl=3000;
78 input;
79 put _infile_;
80 run;
81%end;
82
83%local platform; %let platform=%mf_getplatform();
84%if &platform=SASVIYA %then %do;
85 %if "&path"="HOME" %then %let path=/Users/&sysuserid/My Folder;
86 %mv_createjob(path=&path
87 ,name=&name
88 ,code=&tempref
89 ,desc=&desc
90 ,replace=&replace
91 )
92%end;
93%else %if &platform=SASJS %then %do;
94 %if "&path"="HOME" %then %let path=/Users/&_sasjs_username/My Folder;
95 %ms_createfile(&path/&name..sas
96 ,inref=&tempref
97 ,mdebug=&mdebug
98 )
99%end;
100%else %do;
101 %if "&path"="HOME" %then %let path=/User Folders/&_METAPERSON/My Folder;
102 %mm_createstp(stpname=&name
103 ,filename=&tmpfile
104 ,directory=&work
105 ,tree=&path
106 ,stpdesc=&desc
107 ,mDebug=&mdebug
108 )
109%end;
110filename &tempref clear;
111%mend mx_createjob;