In this string:
Staging.credit_card_account_h_&&M&month._YYMMDD
SAS needs to know where the name of the macro variable that the & is referencing ends. The period after MONTH shows SAS that the macro variable is named MONTH and not MONTH_YYMMDD.
On the second pass attempt to resolve the macro variable references the string has now become
Staging.credit_card_account_h_&M1_YYMMDD
So this will look for a macro variable named: M1_YYMMDD
Do you have such a macro variable (series of macro variables)?
M1_YYMMDD
M2_YYMMDD
M3_YYMMDD
...
Or do you have a series of macro variables named M1, M2, M3 etc?
If the later then you need the second period so that the intermediate string is like this:
Staging.credit_card_account_h_&M1._YYMMDD
So that SAS will look for M1 macro variable instead of M1_YYMMDD macro variable.
When you say that the program worked, can I assume you mean that it ran without error and also produced the correct result?
I can give you the brief explanation. But you will have to find the materials, study them, and know them. There is no way that my knowledge will help you enough to work with these programs.
Here is the brief summary.
When referring to a macro variable, the . at the end of the name is optional. Both of these refer to the macro variable MONTH:
&month
&month.
Sometimes the dot is required to let SAS know what the the name of the macro variable is. In this phrase, SAS won't know:
&month_YYMMDD
SAS will assume that the name of the macro variable is the whole string so the name of the macro variable is month_YYMMDD
By adding a dot, you can instruct SAS that this is not the case:
&month._YYMMDD
The dot tells SAS that the name of the macro variable is month, and the characters _YYMMDD are just part of the program but not part of the name of the macro variable.
You must learn this, or else you will be confused by virtually every macro program you encounter.
Another option is to turn on the macro debugging options with this command.
options mprint symbolgen;
Run the code again, and the log will show you what the values of these macro variables are and the SAS code that is created.
@HeatherNewton wrote:
One more strange thing
One dataset is with a extra &
Instead of the common
Monthly.score_New_hkg_&P_YYMMDD. Where &P_YYMMDD. Is a date
I have this Monthly.score_New_hkg_&&P_YYMMDD.
I believe actuallu
&&P_YYMMDD. = &P_YYMMDD.
Right?? What is the purpose of putting two & here?
Purpose? Without seeing an entire program from start to finish and example data I would hesitate to make any guess on a very partial description of a program.
If the author of the program doesn't document what blocks of code are to accomplish it can be very hard to follow enough logic as to what is going on. Add in the macro language and indirect references of macro variables (i.e. the && or &&& or &&&& or what may appear) then guesses may be all you get.
I think @PaigeMiller may have the right idea: turn on the macro creation information with the MPRINT SYMBOLGEN options to follow the construction of the variables. Then be prepared to spend a lot of time following the original authors code and try to determine the though processes behind what was done.
SAS supports a limited number of so-called "generic" macro variables. But not in this case. The SAS-supplied variable names begin with "sys": &syserr, &sysrc, etc. If you can't find where the macro variable is created, keep looking. It's out there somewhere.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.