BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tdegen
Calcite | Level 5

 

I have a %macro that appends the Labels and Formats to my data files - it works flawlessly if I hard-code the file names.   I need it to be more dynamic.


** THIS CODE WORKS **

%AppendFormatToCatalog(ct14547_0222_ae_v, ct_ae_v_formats, ct_ae_v_labels);
%AppendFormatToCatalog(ct14547_0222_inf_v, ct_inf_v_formats, ct_inf_v_labels);
...
.. * 6 more like these;
.

** THIS CODE FAILS **

%let varName = ct14547_0222;

%AppendFormatToCatalog(&varName_ae_v, ct_ae_v_formats, ct_ae_v_labels);
%AppendFormatToCatalog(&varName_inf_v, ct_inf_v_formats, ct_inf_v_labels);
...
.. * 6 more like these;
.


We get new studies every week and the study file formats are exactly the same each week - with a different name. If I choose to hard-code the study name everything works, but the name ct14547_0222 is referenced like 30 times in my script.  

 

If I use the "%let varName = ct14547_0222;" bit at the top of my code I can get my script to work *except* for this series of macro calls.

 

How can I get "&varName_ae_v" to resolve to "ct14547_0222_ae_v" in a parameter call so it sends the correct parameter to the macro?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You only defined the macro variable varName.

But in the later macro calls you are trying to reference other macro variables with longer names, varName_ae_v.

To tell the macro processor where the name of the macro variable ends use a period.

%AppendFormatToCatalog(&varName._ae_v, ct_ae_v_formats, ct_ae_v_labels);

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You only defined the macro variable varName.

But in the later macro calls you are trying to reference other macro variables with longer names, varName_ae_v.

To tell the macro processor where the name of the macro variable ends use a period.

%AppendFormatToCatalog(&varName._ae_v, ct_ae_v_formats, ct_ae_v_labels);

 

tdegen
Calcite | Level 5

Thank you!  Issue resolved.

 

I have to admit that after reading your response at first I thought I hadn't explained my issue adequately.   But I did a little digging on macro variables and the dot ( . ) suffix.  Your assessment was, of course, 100% correct.

 

This was the second page I looked at:

https://communities.sas.com/t5/SAS-Programming/When-is-proper-time-to-add-dot-after-macro-variables/...

 

I only mention the URL above as it addresses the flaw outside the bounds of today's issue and will change how I declare and use variables.

 

Thank you for correcting my issue and turning me onto a more permanent solution for handling macro variables. 

 

 

 

ballardw
Super User

Did your log show any notes about undefined macro variables?

 

That is your first step, read the log. When you don't understand what the log is telling you then copy the message text with the code generating the message you don't understand and post that in a text box on the forum.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 695 views
  • 0 likes
  • 3 in conversation