I tried to get the first day of current quarter with this code.
%let q1=intnx('qtr', today(),0,'b');
%put &q1;
This gives me the result:
01JAN1960:06:08:17.000 instead of 01JUN2020:00:00:00
I cannot see how the code you show produces anything that looks like a date or datetime value. You need a %sysfunc or two. Are you sure that is the exact code you are using?
This code works for me:
%let q1=%sysfunc(intnx(qtr,%sysfunc(today()),0,b));
%put &=q1;
You want to use a date format, not a datetime format.
@sasuser381 wrote:
Well i need datetime format actualy as an output. How could i do that? Obviously not this way i did.
You need to use datetime values (number of seconds) not date values (number of days) with the DATETIME format. Use the DTQTR interval instead of the QTR interval when working with seconds instead of days.
340 data _null_; 341 now=datetime(); 342 qtr=intnx('dtqtr',now,0,'b'); 343 put (now qtr) (datetime19.); 344 run; 24JUL2020:09:49:55 01JUL2020:00:00:00
%let q1=%sysfunc(intnx(qtr,%sysfunc(today()),0,b),datetime20.);
/* %let q1=intnx('qtr', today(),0,'b'); */
%put &q1;
In SAS macro code you need to wrap datastep function in %sysfunc unless you have macro equivalent such as %scan. In your case it will be
%let q1=intnx('qtr', %sysfunc(today()) ,0,'b');
%put &q1;
1. Functions need to be wrapped in %SYSFUNC()
2. For datetime variables the increment needs to start with DT
3. When using functions within macro code, you do not need quotes.
4. TODAY() returns a DATE variable, if you want DATETIME use DATETIME() function instead.
%let q1=%sysfunc(intnx(dtqtr, %sysfunc(datetime()), 0, b), datetime.);
%put &q1.;
Results:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 %let q1=%sysfunc(intnx(dtqtr, %sysfunc(datetime()), 0, b), datetime.); 70 71 %put &q1.; 01JUL20:00:00:00 72 73 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 83
@sasuser381 wrote:
I tried to get the first day of current quarter with this code.
%let q1=intnx('qtr', today(),0,'b'); %put &q1;
This gives me the result:
01JAN1960:06:08:17.000 instead of 01JUN2020:00:00:00
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.