I didn't include a loop in my code to check keep going through all the scheduler job results. The below code has such a loop:
%let baseurl=%sysget(SAS_SERVICES_URL);
filename headout;
filename headout temp;
filename resp;
filename resp temp;
/* Define a macro */
%macro getsched();
/* Call the URL for this job to get its jobRequest ID */
proc http url="&baseurl&SYS_JES_JOB_URI" oauth_bearer=sas_services out=resp headerout=headout HEADEROUT_OVERWRITE;
headers "Accept"="application/json";
run;
/* Read in the response using the JSON libname engine. */
libname resp;
libname resp json fileref=resp;
/* Pull the ID into the macro variable "id" */
proc sql noprint;
select id into:id from resp.jobrequest ;
quit;
/* Call /scheduler/jobs to get all the scheduled jobs. */
proc http oauth_bearer=sas_services url="&baseurl/scheduler/jobs" out=resp headerout=headout HEADEROUT_OVERWRITE;
headers "Accept"="application/json";
run;
/* Read in the response using the JSON libname engine. */
libname resp;
libname resp json fileref=resp;
/* Read in the "next" URL for scheduler if present, this means we might have to keep looking for the jobRequest */
%let next=;
data _null_;
set resp.links;
if rel="next" then call execute('%let next=%nrstr('||href||')');
run;
/* Try to find the ordinal for the job request in the list of schedules. */
proc sql noprint;
select ordinal_items into:ordinal from resp.items_request where uri="/jobExecution/jobRequests/&id/jobs";
quit;
/* If we find it, then create a macro variable "retype" that gives us the type of the reoccurrence (daily,hourly,etc) */
%if %symexist(ordinal) %then %do;
proc sql noprint;
select b.type into:retype from resp.items_triggers as a,resp.triggers_recurrence as b where a.ordinal_items=&ordinal and a.ordinal_triggers=b.ordinal_triggers;
quit;
%end;
/* If not, we need to check the next URL, or stop if there isn't one. */
%else %do %while (%length(&next)>0);;
/* Call the next URL we pulled earlier. */
proc http oauth_bearer=sas_services url="&baseurl&next" out=resp headerout=headout HEADEROUT_OVERWRITE;
headers "Accept"="application/json";
run;
/* Read in the response using the JSON libname engine. */
libname resp;
libname resp json fileref=resp;
/* Empty the next variable from before. */
%let next=;
/* Try to find the ordinal in this response. */
proc sql noprint;
select ordinal_items into:ordinal from resp.items_request where uri="/jobExecution/jobRequests/&id/jobs";
quit;
/* If it exists, write the retype variable. */
%if %symexist(ordinal) %then %do;
proc sql noprint;
select b.type into:retype from resp.items_triggers as a,resp.triggers_recurrence as b where a.ordinal_items=&ordinal and a.ordinal_triggers=b.ordinal_triggers;
quit;
%end;
/* If not, read the next URL to pull the next set of schedules and continue the loop. */
%else %do;
data _null_;
set resp.links;
if rel="next" then call execute('%let next=%nrstr('||href||')');
run;
%end;
%end;
%if %symexist(retype) %then %put NOTE: Reoccurence type: %trim(&retype);
%else %put WARN: No reoccurence set. This job is not scheduled.;
%mend getsched;
%getsched();
... View more