BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
I have a variable
Staging.credit_card_account_h_&&M&month._YYMMDD.

How do I interpret this date with so many & ?
11 REPLIES 11
Astounding
PROC Star
Most likely you were careless when posting the code. I expect there are actually two dots not 1: &&M&month.. probably you have 13 macro variables:
M1 through M12
month (probably a number from 1 to 12, referred to as &month.)

If you need to work with this program, you absolutely must look up and understand how to resolve &&M&month.
When &month is 1, it resolves to &M1 which then re-resolves into the value of the macro variable M1
You need to acquire some familiarity with macro language, or else you will need to ask questions every time.



HeatherNewton
Quartz | Level 8
It reslly us just 1 . at the end and still work

What is significance of this .

What is difference between one or two dots?

Let say instead of &month. I just have &month without . , would it work too? Is it just part of variable name? What about the . After yymmdd at the very end?
Tom
Super User Tom
Super User

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.

 

 

Astounding
PROC Star

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.

Ksharp
Super User


%let month=1 ;
%let M1_YYMMDD=X ;


credit_card_account_h_&&M&month._YYMMDD.
->credit_card_account_h_&M1_YYMMDD.
->credit_card_account_h_X

But I think Astounding is right .There should be double point :
"&&M&month.."
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
HeatherNewton
Quartz | Level 8
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?
Ksharp
Super User
"&&P_YYMMDD. = &P_YYMMDD.
Right?? What is the purpose of putting two & here?"

Right. Maybe the coder don't know macro language very well .
ballardw
Super User

@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.

 

 

HeatherNewton
Quartz | Level 8
I have another variable

Staging.MY_credit_&yymmdd.

But i couldnt find where is this macro variable being defined, could this be some generic macro variable not needing definition eg %let yymmdd = xxx kind of statement?
Astounding
PROC Star

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.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

Register now

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
  • 11 replies
  • 1976 views
  • 2 likes
  • 6 in conversation