- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I came across a wierd situation. Can someone explain me this?
One of our prod jobs is using %let statement as below and it works
%let rundt = today();
however, when i run the same &rundt resolves to today() and not actual date of today.
I've to use %let rundt = %sysfunc(today());
why is it that it works without %sysfunc in other jobs?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The statements do the same thing, whether it is in your job or in a production job. Whenever you see this statement:
%let rundt = today();
the value of &RUNDT is not a number, but is the 7 characters "today()".
What you are not observing is how the production program uses &RUNDT. For example, it may use this statement in a DATA step:
date = &RUNDT;
In that case, the statement resolves into:
date = today();
When that statement appears in a DATA step, it executes and DATE receives the proper numeric value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The statements do the same thing, whether it is in your job or in a production job. Whenever you see this statement:
%let rundt = today();
the value of &RUNDT is not a number, but is the 7 characters "today()".
What you are not observing is how the production program uses &RUNDT. For example, it may use this statement in a DATA step:
date = &RUNDT;
In that case, the statement resolves into:
date = today();
When that statement appears in a DATA step, it executes and DATE receives the proper numeric value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!
One more question
Why am i not able to use below statement?
%let month1x = %sysfunc(month(today()));
where as, I'm able to use
data _null_ ;
call symput('month1x',month(today()));
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You'll need to use %SYSFUNC for each function ... once for MONTH and once for TODAY. I hope I get the number of parentheses correct:
%let month1x = %sysfunc(month(%sysfunc(today())));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!
I was able to get same results using both ways below. However, I had to use ' ' quotes around month in intnx function for call symput and not for %sysfunc.
Can you tell me the reason why?
%let month2 = %sysfunc(month(%sysfunc(intnx(month,%sysfunc(today()),-1))));
%put &month2;
data _null_;
call symput ('month1',month(intnx('month',today(),-1)));
run;
%put &month1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Except in rare cases where a number is required, macro language assumes all strings are text. Easy examples:
%let name=Fred;
%let name="Fred";
The first statement assigns &NAME a 4-character value. The second assigns &NAME a 6-character value. The quotes are not needed to identify a string, and so become part of the value assigned to &NAME.
You're looking at the same principle, but in a more complex setting.