Hello,
I am trying to use an explicit date I put into a macro variable to name columns with proc sql;. I keep getting an error I can't figure out.
%let currentdatadate=31MAY2022
select
datefield as ¤tdatadate._NEXT_DUE_DATE format=mmddyy10.
from table
;
quit;
I am getting the following error:
Being able to name the columns dynamically would be ideal. Hoping someone can help me figure this out.
Thanks!
When you use a macro variable like ¤tdatadate, and then run the program, SAS replaces the macro variable with its value. After this replacement you MUST have legal valid working SAS code and you do not have this. You are trying to name a variable as 31MAY2022_NEXT_DUE_DATE, this is not a valid variable name. Can you figure out why this is not valid?
Also, @elwayfan446 , in the future, DO NOT show us partial logs. Show us the ENTIRE log for the PROC or DATA step that has the error. Please do this every single time. Do not make us ask repeatedly.
Also, @elwayfan446 , do not show us code that is different than what you actually ran. The code you showed us is missing a semi-colon and is missing PROC SQL and possibly other things. Show us the code you actually ran from now on.
The name of a variable in a SAS data set can not begin with a letter.
When you use a macro variable like ¤tdatadate, and then run the program, SAS replaces the macro variable with its value. After this replacement you MUST have legal valid working SAS code and you do not have this. You are trying to name a variable as 31MAY2022_NEXT_DUE_DATE, this is not a valid variable name. Can you figure out why this is not valid?
Also, @elwayfan446 , in the future, DO NOT show us partial logs. Show us the ENTIRE log for the PROC or DATA step that has the error. Please do this every single time. Do not make us ask repeatedly.
Also, @elwayfan446 , do not show us code that is different than what you actually ran. The code you showed us is missing a semi-colon and is missing PROC SQL and possibly other things. Show us the code you actually ran from now on.
I didn't realize that a macro resolved in a way that would make the variable name invalid when it resolved because of the date being in front. I moved the date to the back end of the name and it worked well.
In regards to the log, I shared the part that was relevant to the issue. I work for a company where information in the log could and often is not allowed to be shared. If I am missing something in the log that anyone here feels necessary to help, I will do my best to share it if I can. If it is too hard to answer without the entire log, I'll understand those who don't want to waste their time trying to help.
As for this issue, thank you for helping me realize the simple mistake I was making with the date resolving as an incorrect variable name.
@elwayfan446 wrote:
I didn't realize that a macro resolved in a way that would make the variable name invalid when it resolved because of the date being in front. I moved the date to the back end of the name and it worked well.
Not sure I agree with this wording. The macro variable resolved properly. The usage was incorrect, it has nothing to do with macro variables resolving. As I said, you have to be sure that after the macro variable resolves, the resulting SAS code must be legal valid working SAS code.
Also, let's straighten out terminology. You are not using a macro. You are using a macro variable. These are not the same.
You help yourself get faster and better answers by showing us full logs (if possible), the code you actually used, and by using proper terminology. This helps you, this helps us. If you don't want to help us and help yourself, that's not good.
In this specific case, the problem could be solved without the full log, that will not be true in other cases.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.