BookmarkSubscribeRSS Feed

SAS Viya: Send Email Custom Step Featuring the Color Picker Control

Started ‎10-19-2022 by
Modified ‎04-12-2023 by
Views 2,326

With the August 2022 stable release (2022.1.4) there is now the capability to use the color picker control to select a color in a custom step.  Typical examples would include using the color picker control to select the color for a graph or report; however, in this post, I will demonstrate using the color picker control to select the color for the text of an email.


UI Design


For the user interface design, I create a page with the essential email information.



Copy Recipients section collapsed



Copy Recipients section expanded


Notice that the Body section has a note that if you want this text in a different use the color selector on the Options tab.  


On the Options tab, not only is there the color picker control to select the text color for the email message, but there is also the selection of the importance of the email and whether to request a read receipt for the message.




There is also an Email Setup tab, to specify the SMTP mail host and port information.




The About tab provides information about what the custom step does.  It is a recommended best practice to add this to all your custom steps.






Below is a screenshot of the Program code to send the email message with the selected options from the user interface.  I have highlighted where the color picker value is referenced in the code.




Here is the full Program code for the Send SMTP Email custom step:


/* Set email options */
/* if emailBody_count is empty (doesnt exist) create it and create emailBody_1 */
%global emailBody_count ;
%if &emailBody_count eq %then %do ; 
	%let emailBody_count=1 ;
	%let emailBody_1=&emailBody ;
%end ;
/* Format input information if multiple email addresses entered */
data _null_ ;
    newEmailTo=cats(transtrn(strip(compbl(translate("&emailTo"," ",",")))," ",'" "')) ;
    call symput('emailTo',strip(newEmailTo)) ;
    newEmailCC=cats(transtrn(strip(compbl(translate("&emailCC"," ",",")))," ",'" "')) ;
    call symput('emailCC',strip(newEmailCC)) ;
    newEmailBCC=cats(transtrn(strip(compbl(translate("&emailBCC"," ",",")))," ",'" "')) ;
    call symput('emailBCC',strip(newEmailBCC)) ;
run ;
/* Format and send email */
filename outmail email
 	importance="&importance" /* Low Normal High.  Default is Normal */
	/* If ReadReceipt option is checked */
	%if &readReceipt %then %do ;
	%end ;
/* Build the body of the email */
data _null_ ;
	file outmail ;
	put "<html><body>" ;
    put "<p style='color: #&textColor'>" ;
	do i = 1 to &emailBody_count ;
        if symget("emailBody_" || strip(put(i,12.))) eq '' then do ;
			text=cats("<br>") ;
        end ;
        else do ;
			text=cats(symget("emailBody_" || strip(put(i,12.))),"<br>") ;
		end ;
		put text ;
	end ;
    put "</p>" ;
	put "</body></html>" ;

/* Clear macro */
%symdel emailBody_count ;


Test the Custom Step


The easiest method for testing a custom step is to open it in stand-alone mode. 


For more information, on this refer to my previous post.   To open the Send SMTP Email custom step in stand-alone mode, I right-click the custom step and select Open in a tab menu option.


I enter the following information on the Email Message Information tab:




I enter the following information on the Options tab:




Note that I have selected a color for the email text using the color picker control.  


I enter the following information on the Email Setup tab:




  I select the Run button to execute the custom step.  Below is the email I received by running the Send SMTP Email custom step.





Note the message was sent with High importance and the text color is the color specified in the options of the custom step.  




The color picker control is now available for use in custom steps.  For more information on the color picker control review its documentation: SAS Help Center: Color Picker Control.  


  The Send SMTP Email custom step I highlighted in this blog can be downloaded from here.  


Thanks to my colleague, @NicolasRobert , for his programming assistance with this custom step!  

Version history
Last update:
‎04-12-2023 10:52 AM
Updated by:



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags