All,
Here is a question that I am struggling with. I would like to find the last day of the month in a different time zone. I know there are countless examples using intnx() which show how to compute the last day of the month. I tried to apply the same concept as shown in one such example. Here is my code:
/*%Let T = %sysfunc(tzoneu2s(%sysfunc(tzones2u(%sysfunc(datetime()))),asia/singapore));
%Put Test: &T;
%Let T1 = %sysfunc(intnx('dtmonth', &T, 0, 'E'));
%Put Test1: &T1;*/
I receive a warning which says:
%Let T = %sysfunc(tzoneu2s(%sysfunc(tzones2u(%sysfunc(datetime()))),asia/singapore),datetime.);
%Put Test: &T;
%Let T1 = %sysfunc(intnx('dtmonth', &T, 0, 'E'));
%Put Test1: &T1;
Any help or advice is appreciated. Thanks in advance.
Best
Uday
Important rule: do not format your dates or datetimes to be human readable when writing macro code. The only time they need to be formatted for human readability is when you are either inputting the date/datetime or outputting the date/datetime.
%Let T = %sysfunc(tzoneu2s(%sysfunc(tzones2u(%sysfunc(datetime()))),america/los_angeles));
By the way, please don't show us your SASLOG as a (hard-to-read) screen capture. SAS LOG ought to copied as text and pasted into the window that appears when you click on the {i} icon.
Do not use quotes inside of %sysfunc
%Let T1 = %sysfunc(intnx(dtmonth, &T, 0, E));
@PaigeMiller,
Thank you for your response. I updated the code according to your suggestion and still receive the same error.
%Let T = %sysfunc(tzoneu2s(%sysfunc(tzones2u(%sysfunc(datetime()))),america/los_angeles),datetime.);
%Put Test: &T;
%Let T1 = %sysfunc(intnx(dtmonth, &T, 0, E));
%Put Test1: &T1;
Important rule: do not format your dates or datetimes to be human readable when writing macro code. The only time they need to be formatted for human readability is when you are either inputting the date/datetime or outputting the date/datetime.
%Let T = %sysfunc(tzoneu2s(%sysfunc(tzones2u(%sysfunc(datetime()))),america/los_angeles));
By the way, please don't show us your SASLOG as a (hard-to-read) screen capture. SAS LOG ought to copied as text and pasted into the window that appears when you click on the {i} icon.
Hello,
Apart from @PaigeMiller suggestion, you need to tell SAS that your are giving datetime vaues.
%Let T = %sysfunc(tzoneu2s(%sysfunc(tzones2u(%sysfunc(datetime()))),asia/singapore),datetime.);
%Put Test: &T;
/* You need to tell SAS that its a datetime value ("datetime value"dt)*/
/* Since the macro variable T has a value in date time */
%Let T1 = %sysfunc(intnx(dtmonth, "&T"dt, 0, E));
%Put Test1: &T1;
Another approache, leave them as SAS numeric date values and avoid giving the format.
/* In this example the macro varible simply holds numeric value, no format */
%Let T = %sysfunc(tzoneu2s(%sysfunc(tzones2u(%sysfunc(datetime()))),asia/singapore));
%Put Test: &T;
%Let T1 = %sysfunc(intnx(dtmonth,&T, 0, E));
%Put Test1: &T1;
/* Note: T1 is a numeric value that represent SAS Date, you may later need to apply format to it*/
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.