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 @li mf_getuniquefileref.sas
31
32 @param [in,out] path= The full folder path where the job will be created
33 @param [in,out] name= Job name. Avoid spaces.
34 @param [in] desc= The description of the job (optional)
35 @param [in] precode= Space separated list of filerefs, pointing to the code
36 that needs to be attached to the beginning of the job (optional)
37 @param [in] code= (ft15f001) Space seperated fileref(s) of the actual code to
38 be added
39 @param [in] replace= (YES) Select YES to replace any existing job in that
40 location
41 @param [in] mDebug= (0) set to 1 to show debug messages in the log
42
43 @author Allan Bowe
44
45 <h4> Related Macros </h4>
46 @li mx_createjob.test.sas
47 @li mx_createwebservice.sas
48
49**/
50
51%macro mx_createjob(path=HOME
52 ,name=initJob
53 ,precode=
54 ,code=ft15f001
55 ,desc=This job was created by the mx_createjob macro
56 ,replace=YES
57 ,mdebug=0
58)/*/STORE SOURCE*/;
59
60%if &syscc ge 4 %then %do;
61 %put syscc=&syscc - &sysmacroname will not execute in this state;
62 %return;
63%end;
64
65/* combine precode and code into a single file */
66%local tempref x fref freflist;
67%let tempref=%mf_getuniquefileref();
68%local work tmpfile;
69%let work=%sysfunc(pathname(work));
70%let tmpfile=&tempref..sas;
71filename &tempref "&work/&tmpfile";
72%let freflist=&precode &code ;
73%do x=1 %to %sysfunc(countw(&freflist));
74 %let fref=%scan(&freflist,&x);
75 %put &sysmacroname: adding &fref;
76 data _null_;
77 file &tempref lrecl=3000 termstr=crlf mod;
78 infile &fref lrecl=3000;
79 input;
80 put _infile_;
81 run;
82%end;
83
84%local platform; %let platform=%mf_getplatform();
85%if &platform=SASVIYA %then %do;
86 %if "&path"="HOME" %then %let path=/Users/&sysuserid/My Folder;
87 %mv_createjob(path=&path
88 ,name=&name
89 ,code=&tempref
90 ,desc=&desc
91 ,replace=&replace
92 )
93%end;
94%else %if &platform=SASJS %then %do;
95 %if "&path"="HOME" %then %let path=/Users/&_sasjs_username/My Folder;
96 %ms_createfile(&path/&name..sas
97 ,inref=&tempref
98 ,mdebug=&mdebug
99 )
100%end;
101%else %do;
102 %if "&path"="HOME" %then %let path=/User Folders/&_METAPERSON/My Folder;
103 %mm_createstp(stpname=&name
104 ,filename=&tmpfile
105 ,directory=&work
106 ,tree=&path
107 ,stpdesc=&desc
108 ,mDebug=&mdebug
109 )
110%end;
111filename &tempref clear;
112%mend mx_createjob;