BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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: 

WARNING: Argument 1 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set
to a missing value.

   Alternatively, if I format "T" as a date time as shown below, that results in an errror: 
 
%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;
ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.

 Any help or advice is appreciated. Thanks in advance. 

Best 
Uday 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Do not use quotes inside of %sysfunc

 

%Let T1 = %sysfunc(intnx(dtmonth, &T, 0, E));
--
Paige Miller
UdayGuntupalli
Quartz | Level 8

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

image.png

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
SuryaKiran
Meteorite | Level 14

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*/
Thanks,
Suryakiran

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 643 views
  • 4 likes
  • 3 in conversation