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?
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);
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);
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:
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.
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.
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.