BookmarkSubscribeRSS Feed
gleebglorb
Calcite | Level 5

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?

2 REPLIES 2
Reeza
Super User

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?


 

Astounding
PROC Star

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1424 views
  • 0 likes
  • 3 in conversation