Published on :
Macro CREATION_INTERNE

SAS Viya Job Code Retrieval Test

This code is also available in: Deutsch Español Français
Awaiting validation
This script aims to test the `mv_getjobcode` macro. It proceeds in three steps: 1) Creation of a file containing arbitrary SAS© code and deployment of this code as a SAS© Viya Job via `mv_createjob`. 2) Retrieval of the Job's code into a fileref via `mv_getjobcode`, while monitoring macro variable pollution with `mp_assertscope`. 3) Comparison of the retrieved code with the original code via a DATA step and final validation with `mp_assert`.
Data Analysis

Type : CREATION_INTERNE


The script generates its own test data (SAS code stored in a variable) and uses temporary system files.

1 Code Block
DATA STEP
Explanation :
Definition of a test SAS code string and writing this string to a temporary file via a DATA _NULL_ step.
Copied!
1%let incode=%str(DATA test; SET sashelp.class;RUN;);
2filename testref temp;
3DATA _null_;
4 file testref;
5 put "&incode";
6RUN;
2 Code Block
MACRO CALL
Explanation :
Call to the `mv_createjob` macro to create a SAS Viya Job at the specified test location, containing the previously defined code.
Copied!
1%mv_createjob(
2 code=testref,
3 path=&mcTestAppLoc/services/temp,
4 name=some_job
5)
3 Code Block
MACRO CALL
Explanation :
Take a snapshot of macro variables, call the tested function `mv_getjobcode` to retrieve the job's code into the 'mycode' fileref, then verify that no unexpected macro variables have been created (scope leak).
Copied!
1%mp_assertscope(SNAPSHOT)
2%mv_getjobcode(
3 path=&mcTestAppLoc/services/temp,
4 name=some_job,
5 outref=mycode
6)
7%mp_assertscope(COMPARE,
8 ignorelist=MCLIB2_JADP1LEN MCLIB2_JADP2LEN MCLIB2_JADPNUM MCLIB2_JADVLEN
9 MCLIB2_JADP3LEN
10)
4 Code Block
DATA STEP Data
Explanation :
Read the retrieved code (fileref 'mycode') and compare it line by line with the original string stored in the 'incode' macro variable. If a match, update the success flag.
Copied!
1%let diditexist=NO;
2DATA work.test1;
3 INFILE mycode;
4 INPUT;
5 putlog _infile_;
6 line=_infile_;
7 check=symget('incode');
8 IF _infile_=symget('incode') THEN call symputx('diditexist','YES');
9RUN;
5 Code Block
MACRO CALL
Explanation :
Final assertion to validate that the test was successful (the code was correctly retrieved).
Copied!
1%mp_assert(
2 iftrue=(&diditexist=NO),
3 desc=Check IF the code that was sent was successfully retrieved
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.