BookmarkSubscribeRSS Feed
🔒 This topic is locked. We are no longer accepting replies to this topic. Need further help? Please sign in and ask a new question.
SAS_Tipster
Moderator

Quite often it is necessary to set a default value for a macro variable or parameter that is passed to a program. If the program is a macro, the %IF statement can be used to check if the value is provided and provide a default value if not. Since the %IF statements are not allowed outside of macros, that technique won't work for a non-macro program (e.g., a file/program that is %INCLUDEd). The following code snippet demonstrates the use of the coalescec function to assign a default value.

%global myParameter;  /* ensure it exists */
%let myParameter = %sysfunc(coalescec(&myParameter,defaultValue));

If the myParameter macro variable has a value, it will be used, otherwise defaultValue will be assigned as the value. This technique can also be used in macros instead of using a %IF statement.

 

The coalescec function is used regardless of whether the expected value for the parameter is numeric since macro is a text manipulation facility, (i.e., everything in macro is interpreted as a character string).


Thanks to Don Henderson for sharing this tip on sasCommunity.org.

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 lock in 2025 pricing—just $495!

Register now

Visit a random SAS tip This SAS Tips board is not open for replies or comments, but we welcome your feedback and questions. Have a question or comment about this tip? Start a new topic in one of our discussion boards, and reference this tip topic.
Discussion stats
  • 0 replies
  • 6366 views
  • 0 likes
  • 1 in conversation