- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The name of a variable in a SAS data set can not begin with a letter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would suggest that if you find a question that frustrates you this much in the future... just scroll on by. There are plenty of people that don't mind helping without making it such an issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want variable names that begin with numbers, you need to change the VALIDVARNAME option to ANY
However, this means you need to work with variable names as named literals, which is something that SAS EG does more nicely than Display Manager...
options validvarname=any;
data test;
input '1x'n;
cards;
1
2
3
;
run;