BookmarkSubscribeRSS Feed

It’s About Time: Using Date Values in SAS Viya Job Forms

Started 4 hours ago by
Modified 4 hours ago by
Views 119

Forms and prompts make SAS Viya jobs flexible and interactive. They let users select filters, parameters, and options before a job runs. Whether you’re building a report that returns sales for a specific day, or a process that summarizes data between two dates, date controls let users supply that information directly in the job interface. In SAS Viya, you can add date controls to both HTML forms and JSON-based step prompts. In this article, I’ll discuss how to create date selection controls, and how to handle the parameter values they generate in a job definition.

 

 

Adding an HTML Date Control

 

To build a date control in an HTML form, use the <input> element with the type attribute set to date.

 

Here’s a simple example:

 

<label for="startDate">Select a start date:</label>
<input type="date" id="startDate" name="startDate">

 

Which creates the following control:

 

01_treiman_date1.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

The name attribute must match the macro variable you plan to reference in your SAS code — in this case, selectDate.

 

You can also:

 

  • Restrict the range of available values using min and max
  • Set a default with the value attribute
  • Capture both date and time using type="datetime-local"

 

These options make it easy to tailor your input to the needs of your job.

 

Adding a Step Prompt Date Control

 

Date controls can also be used in JSON-based prompt forms. You can use the Date and Time Picker control to allow the user to select date or time values.

 

This control supports:

 

  • date, time, datetime, and month types
  • Minimum and maximum values to limit the available values
  • Default selections

 

Forms built using the Date and Time Picker control look like this:

 

02_treiman_date2.png

 

Like with the HTML control, the ID value used by the picker must match the macro variable used in the program code.

 

 

Handling Date Parameters in Your SAS Code

 

Whether you use a JSON form or an HTML form, you need to consider how the parameter values are passed to the code. Once a user selects a date, the macro variable received by the SAS job looks like this:

 

2020-01-01

 

The macro variable containing the date selection is not a SAS date value – in other words, it is not numeric. Since SAS stores dates as the number of days since January 1, 1960, you need to convert the value before using it in expressions or comparisons.

 

There are a few ways to handle this. You can use the INPUT function with an appropriate informat wherever you reference the date:

 

where Date = input("&selectDate", yymmdd10.);

 

While this technique works, it means you must repeat the conversion each time you use the variable.

 

Another approach is to convert the date once at the top of the program and store it in a new macro variable:

 

%let SASDate = %sysfunc(inputn("&selectDate", yymmdd10.));

 

Now you can use &SASDate anywhere in your code, and it behaves as a numeric SAS date:

 

where Date >= &SASDate;

 

This makes your code easier to read and maintain.

 

 

Conclusion

 

Working with date values in SAS Viya jobs isn’t complicated, but it’s important to be aware of how SAS represents time. By setting up your input form carefully and converting user-provided dates to numeric SAS dates, you’ll make your jobs more reliable, maintainable, and user-friendly.

 

 

Find more articles from SAS Global Enablement and Learning here.

Contributors
Version history
Last update:
4 hours ago
Updated by:

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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 Tags