How can I create a title based on the values of several macros
I have
%let name = Mary;
%let id = 10021;
%let key = Z;
I want my title to look like this (MaryID10021KeyZ)
How can I make this in the titles statement?
Multiple macro VARIABLEs in a title are perfectly fine.
This may generate what you want. You may find yourself with leading/trailing spaces issues though.
EDIT: note that I added in the periods. It's needed for the ID variable otherwise, SAS cannot tell if the macro variable is ID or IDKEY.
A period at the end of the macro variable name tells SAS that is the end of name and it can be resolved correctly..
title "&name.&ID.Key&Key.";
In that case, it really depends on how you're creating your macro variables. If you can use CALL SYMPUTX() or TRIMMED option in SQL, that's the easiest way to remove the trailing/leading spaces but again, it depends on how you're creating the macro variables.
FYI - I modified your subject line to specify macro variables not macros. There is a significant difference between the two and it's important to be specific for future searches.
UCLA introductory tutorial on macro variables and macros
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/
Tutorial on converting a working program to a macro
This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂 https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md
Examples of common macro usage
https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...
@gleebglorb wrote:
How can I create a title based on the values of several macros
I have
%let name = Mary;
%let id = 10021;
%let key = Z;
I want my title to look like this (MaryID10021KeyZ)
How can I make this in the titles statement?
Perhaps with a slight modification to add ID in the middle:
title "(&name.ID&id.Key&key.)";
This variation supposes that the parentheses are supposed to be part of the title. Take them out if they aren't needed.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.