The script generates its own test data: a temporary file (`testref`) serving as the source code for the job, and datasets (`work.info`, `work.jobstates`) produced by the SAS Viya macros. The content of the job log is also internal data generated by the job's execution.
1 Code Block
DATA STEP Data
Explanation : This block creates a temporary fileref 'testref' and writes a simple SAS program (`data;run; endsas;`) to it. This minimalist SAS program will then be used as the source code for a SAS Viya job.
Copied!
filename testref temp;
data _null_;
file testref;
put 'data;run;';
put 'endsas;';
run;
1
filename testref temp;
2
DATA _null_;
3
file testref;
4
put 'data;run;';
5
put 'endsas;';
6
RUN;
2 Code Block
MACRO mv_createjob
Explanation : Call to the `%mv_createjob` macro to define a new SAS Viya job named 'testjob' at the location specified by the macro variable `&mcTestAppLoc/jobs/temp`. The job's source code is read from the previously created fileref 'testref'.
Explanation : Executes the previously defined job 'testjob'. Detailed job execution information (URI, status, etc.) is saved to the `work.info` dataset.
Explanation : Filters the `work.info` dataset to retain only observations relevant for job status tracking, specifically those where `method` is 'GET' and `rel` is 'state'. This is done in preparation for awaiting the job's final status.
Copied!
data work.info;
set work.info;
where method='GET' and rel='state';
run;
1
DATA work.info;
2
SET work.info;
3
where method='GET' and rel='state';
4
RUN;
5 Code Block
MACRO mv_jobwaitfor Data
Explanation : Call to the `%mv_jobwaitfor` macro to wait for the job, whose information is contained in `work.info`, to reach a final state (ALL). The detailed final status is recorded in the `work.jobstates` dataset.
Explanation : This `DATA _NULL_` step reads the `work.jobstates` dataset and extracts the value of the `uri` variable (the Uniform Resource Identifier of the job's log) to store it in the macro variable `uri`. This macro variable is essential for retrieving the job log.
Copied!
data _null_;
set work.jobstates;
call symputx('uri',uri);
run;
1
DATA _null_;
2
SET work.jobstates;
3
call symputx('uri',uri);
4
RUN;
7 Code Block
MACRO mv_getjoblog
Explanation : The `%mp_assertscope(SNAPSHOT)` macro is used to capture the current state of macro variables, useful for test comparisons. Then, the `%mv_getjoblog` macro is called to retrieve the job log using the previously extracted URI. The log content is saved to the fileref `mylog` with debugging enabled (`mdebug=1`).
Explanation : This `%mp_assertscope(COMPARE...)` macro is used in a unit test context to compare the current state of macro variables with a previous 'snapshot', ignoring certain macro variables (`MCLIB2_JADP2LEN`, `MCLIB2_JADPNUM`, `MCLIB2_JADVLEN`) which are likely automatically generated internal variables and not relevant for the assertion.
Copied!
/* ignore auto proc json vars */
%mp_assertscope(COMPARE
,ignorelist=MCLIB2_JADP2LEN MCLIB2_JADPNUM MCLIB2_JADVLEN
)
Explanation : This `DATA _NULL_` step reads the content of the job log (`mylog`) line by line. It searches for the string 'endsas;'. If found, the macro variable `found` is set to 1. If the end of the file is reached without finding the string, `found` is set to 0. The log content is also written to the current SAS log via `putlog _infile_` for debugging purposes.
Copied!
data _null_;
infile mylog end=eof;
input;
putlog _infile_;
retain found 0;
if index(_infile_,'endsas;') then do;
found=1;
call symputx('found',found);
end;
else if eof and found ne 1 then call symputx('found',0);
run;
1
DATA _null_;
2
INFILE mylog END=eof;
3
INPUT;
4
putlog _infile_;
5
retain found 0;
6
IF index(_infile_,'endsas;') THENDO;
7
found=1;
8
call symputx('found',found);
9
END;
10
ELSEIF eof and found ne 1THEN call symputx('found',0);
11
RUN;
10 Code Block
MACRO mp_assert
Explanation : The `%mp_assert` macro is used to verify a test condition. Here, it checks if the macro variable `found` is equal to 1, which confirms that the string 'endsas;' was found in the job log. The test description indicates that it is to verify if the log was correctly retrieved despite the simplicity of the submitted job.
Copied!
%mp_assert(
iftrue=(%str(&found)=1),
desc=Check if the log was still fetched even though endsas was submitted
)
1
%mp_assert(
2
iftrue=(%str(&found)=1),
3
desc=Check IF the log was still fetched even though endsas was submitted
4
)
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.