Data is entirely generated internally. A temporary SAS program is dynamically created using a `_null_` DATA STEP writing to a `filename temp`. Input parameters for the job flow (`work.inputjobs`) are also created by an explicit DATA STEP. No external files or SASHELP datasets are directly read for the script's main data.
1 Code Block
DATA STEP Data
Explanation : This SAS block creates a temporary file named `testprog` and writes a SAS program to it. This program is designed to simulate a business task that uses macro variables `&_program`, `&flow_id`, `¯ovar1`, and `¯ovar2`. It includes conditional logic where `abort` is triggered if a random value (`rand("uniform")`) is greater than 0.50, thus simulating a job failure. The program also generates an anonymous dataset containing calculated variables (`rval`, `rand`, `y`).
Copied!
filename testprog temp;
data _null_;
file testprog;
put '%put this is job: &_program;'
/ '%put this was run in flow &flow_id;'
/ 'data ;'
/ ' rval=rand("uniform");'
/ ' rand=rval*¯ovar1;'
/ ' do x=1 to rand;'
/ ' y=rand*¯ovar2;'
/ ' if (rval>0.50) then abort;'
/ ' else output;'
/ ' end;'
/ 'run;'
;
run;
1
filename testprog temp;
2
DATA _null_;
3
file testprog;
4
put '%put this is job: &_program;'
5
/ '%put this was run in flow &flow_id;'
6
/ 'data ;'
7
/ ' rval=rand("uniform");'
8
/ ' rand=rval*¯ovar1;'
9
/ ' do x=1 to rand;'
10
/ ' y=rand*¯ovar2;'
11
/ ' if (rval>0.50) then abort;'
12
/ ' else output;'
13
/ ' end;'
14
/ 'run;'
15
;
16
RUN;
2 Code Block
MACRO CALL (mv_createjob)
Explanation : Calls the `%mv_createjob` macro to create a job named 'demo1'. This job is saved to the path '/Public/temp' (likely a folder in a CASLIB) and uses the SAS code generated in the temporary file `testprog` as its source. This macro prepares the job for subsequent execution within a job flow on the SAS Viya environment.
Explanation : Calls the `%mv_createjob` macro again to create a second job named 'demo2', also using the same source code (`testprog`) and the same save path as job 'demo1'. This configures two independent jobs that will be managed by the same execution flow.
Explanation : This DATA STEP creates the `work.inputjobs` dataset. This dataset serves as a dashboard for the job flow, specifying execution parameters for each job instance. It sets the `_contextName` as 'SAS Job Execution compute context', iterates over two distinct `flow_id`s, and for each `flow_id`, prepares executions for 'demo1' and 'demo2' with different values for `macrovar1` and `macrovar2`. This allows testing job behavior with various inputs and simulating multiple executions.
Copied!
data work.inputjobs;
_contextName='SAS Job Execution compute context';
do flow_id=1 to 2;
do i=1 to 4;
_program='/Public/temp/demo1';
macrovar1=10*i;
macrovar2=4*i;
output;
i+1;
_program='/Public/temp/demo2';
macrovar1=40*i;
macrovar2=44*i;
output;
end;
end;
run;
1
DATA work.inputjobs;
2
_contextName='SAS Job Execution compute context';
3
DO flow_id=1 to 2;
4
DO i=1 to 4;
5
_program='/Public/temp/demo1';
6
macrovar1=10*i;
7
macrovar2=4*i;
8
OUTPUT;
9
i+1;
10
_program='/Public/temp/demo2';
11
macrovar1=40*i;
12
macrovar2=44*i;
13
OUTPUT;
14
END;
15
END;
16
RUN;
5 Code Block
MACRO CALL (%put)
Explanation : Displays the current value of the automatic variable `SYSCC` (System Return Code) in the SAS log. `SYSCC` contains the return code of the last system call or macro, serving here as a checkpoint before job flow execution to ensure a known initial state, typically 0 for success.
Copied!
%put NOTE: &=syscc;
1
%put NOTE: &=syscc;
6 Code Block
MACRO CALL (mv_jobflow)
Explanation : Calls the `%mv_jobflow` macro to execute the defined jobs. It takes `work.inputjobs` as the input dataset (`inds`), limits concurrency to 2 parallel jobs (`maxconcurrency=2`), saves results to `work.results` (`outds`), and log information to a fileref `myjoblog` (`outref`). The `raise_err=1` option is crucial because it ensures that errors occurring in the executed jobs are reflected in the `SYSCC` of the calling process, allowing for centralized error handling. `mdebug=1` enables debugging mode for the macro, providing detailed information in the log.
Explanation : Displays the `SYSCC` value after job flow execution. This allows verifying if errors from internal jobs (which may `abort`) were correctly captured and transmitted to the calling process by the `%mv_jobflow` macro, and if `SYSCC` reflects a potential flow failure.
Copied!
%put NOTE: &=syscc;
1
%put NOTE: &=syscc;
8 Code Block
DATA STEP
Explanation : This DATA STEP reads the content of the file referenced by `myjoblog` (which was populated by the `%mv_jobflow` macro and contains the consolidated job flow log) and prints each line (`_infile_`) to the SAS log. This is an essential debugging and verification step to examine messages and statuses generated by jobs executed in the flow.
Copied!
data _null_;
infile myjoblog;
input; put _infile_;
run;
1
DATA _null_;
2
INFILE myjoblog;
3
INPUT; put _infile_;
4
RUN;
9 Code Block
MACRO CALL (mp_assert)
Explanation : Uses the `%mp_assert` macro (likely a custom test or assertion macro) to check a logical condition. Here, it ensures that the `SYSCC` variable is not equal to zero, which would indicate that an error was detected and propagated from the job flow. The `desc` message clarifies the objective: 'Check that a non-zero return code is returned if the called job fails'. This assertion is crucial for validating the robustness of the flow system's error handling.
Copied!
%mp_assert(
iftrue=(&syscc ne 0),
desc=Check that non zero return code is returned if called job fails
)
1
%mp_assert(
2
iftrue=(&syscc ne 0),
3
desc=Check that non zero return code is returned IF called job fails
4
)
10 Code Block
MACRO CALL (%let)
Explanation : Resets the automatic macro variable `SYSCC` to zero. This practice is common at the end of a test or code section to prevent the `SYSCC` from this section from affecting subsequent checks or the overall state of the program being executed.
Copied!
%let syscc=0;
1
%let syscc=0;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.