BookmarkSubscribeRSS Feed

Viya Jobs and Flows: Creating Trigger Files

Started Wednesday by
Modified Wednesday by
Views 161

In a previous post, I demonstrated how to trigger SAS Job Flows with file events. While other file event types exist, I focused on triggering job flows when files arrive....in SAS content.

 

That last bit about SAS content adds a little complexity. So, I provided two methods to produce the SAS content trigger files programmatically, one with base SAS and one with Python. However, I have heard that the file event service does not always detect the base SAS-created files. So, I'll provide a more reliable method here.

 

The code below is an example that you can modify for your own environment.

 

Special thanks to Daniel Kuiper for identifying the issue and coming up with this solution!

 

 

Base SAS - Write a SAS Content File

%let server = server.demo.sas.com;
%let folderId = @public;
%let filename = triggerFlow4.file;
%let boundary = %sysfunc(uuidgen());
 
/*Create Trigger file*/
 
filename inpFile temp;
data _null_;
    file inpfile lrecl=32767 TERMSTR=CRLF;
    put "--&boundary";
    put 'Content-Disposition: form-data; name="file"; filename="' "&filename" '"';
    put "Content-Type: text/plain";
    put;
    dt = put(datetime(),datetime19.);
    put  dt;
    put "--&boundary--";
run;

/* Create a file to hold the web service response */ 
filename resp temp;

/* Post the trigger file to the desired SAS content folder */ 
proc http
    url="https://&server./files/files?parentFolderUri=/folders/folders/&folderId"
    oauth_bearer = sas_services 
    method="POST"
    in=inpfile
    out=resp
    ct="multipart/form-data; boundary=&boundary";
    headers
      "Accept"="application/json";
run;

/* Write the Post response message to the log */ 
data _null_;
    infile resp;
    input;
    put _infile_;
run;

 

Here are a few things to note:

 

  • The code is parameterized. Change the macro variable assignments at the beginning to the values you want or attach them to environment variables and such in your environment
  • The server macro variable is set to the default EDU student server name. So this code will generally work without modification on an EDU server assuming the right SAS components are present on the image
  • The folderId macro variable must be set to the Viya object ID for the SAS content folder where the file will be created. Getting this value is not difficult and a one time task. It can be seen by right-clicking the folder in the Viya UI and selecting "Properties." In this example, we used @public which points to the "Public" folder which is created by default.
  • The code uses the Viya Files REST API to create the trigger file. For more information on the Files API, see this link.
  • The code also uses the Folders API, "?parentFolderUri=/folders/folders/&folderId" to direct the file to the desired Viya content folder. For more information on the Folders API, see this link.
  • Proc Http sends the inpFile file to the Viya API as a request. The request will look like this:
    --eebf3b6a-83c2-ce42-bf7c-69e1c70fd581
    Content-Disposition: form-data; name="file"; filename="triggerFlow4.file"
    Content-Type: text/plain
    09JAN2026:12:03:12
    --eebf3b6a-83c2-ce42-bf7c-69e1c70fd581--
    This is a standard multipart REST format. The datetime will be written into the file contents.
  • The TEMSTR=CRLF file statement option is critical. The message sent must have Windows style line breaks.
  • The oauth_bearer = sas_services option used authenticates the POST request. It indicates that the code is run within a pre-authenticated SAS sever, like running in SAS Studio. If running outside a SAS service, there are numerous other ways to authenticate. One would be to specify your access token in the web service header as shown here.
  • The code includes a data _null_ section at the end to write the response message from the Viya Files service. A successful execution will trigger a message like this:

    {"creationTimeStamp":"2026-01-09T15:46:28.927Z","modifiedTimeStamp":"2026-01-
    9T15:46:28.927Z","createdBy":"sasadm","modifiedBy":"sasadm","id":"dd0e7e12-ee56-
    47ac-9066-60db62265cbc","properties":{},"contentType":"text/plain","encoding":"UTF-
    8","links":[{"method":"GET","rel":"self","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","uri":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","type":"application/vnd.sas.file"},
    {"method":"GET","rel":"alternate","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","uri":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","type":"application/vnd.sas.summary"},
    {"method":"PATCH","rel":"patch","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","uri":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","type":"application/vnd.sas.file","responseType":"application/vnd.sas.file
    "},{"method":"PUT","rel":"update","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","uri":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","type":"application/vnd.sas.file","responseType":"application/vnd.sas.file
    "},{"method":"DELETE","rel":"delete","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc","uri":"/files/files/dd0e7e12-ee56-47ac-9066-60db62265cbc"},
    {"method":"GET","rel":"content","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc/cont
    ent","uri":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc/content","type":"text/plain"},
    {"method":"PUT","rel":"updateContent","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc/content","uri":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc/content","type":"*/*","responseType":"application/vnd.sas.file"},
    {"method":"POST","rel":"copyFile","href":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc/copy","uri":"/files/files/dd0e7e12-ee56-47ac-9066-
    60db62265cbc/copy","responseType":"application/vnd.sas.file"},
    {"method":"POST","rel":"create","href":"/files/files","uri":"/files/files","type":"*/*","respons
    eType":"application/vnd.sas.file"}],"name":"triggerFlow4.file","size":18,"searchable":true,"f
    ileStatus":"unlocked","fileVersion":0,"typeDefName":"file","version":4,"virusDetected":fals
    e,"urlDetected":false,"quarantine":false}

     

     

    Find more articles from SAS Global Enablement and Learning here.

Contributors
Version history
Last update:
Wednesday
Updated by:

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags