data null;
BPM = INTNX('Month',&Rundate,-1,'b'); /*first day last month*/
EPM = INTNX('Month',&Rundate,-1,'e'); /*last day last month*/
CALL SYMPUT('pmb',BPM);
CALL SYMPUT('pme',EPM);
run;
%put &pmb &pme ;
The above datastep will return a 5 digit number that represents the dates (ie 19663)
data date1;
last_month_begin=&pmb;
last_month_end=&pme;
format last_month_begin last_month_end mmddyy10.;
run;
I ran this datastep to convert the results from a number to an actual date format (ie 19663 becomes 11/1/2013)
Is there a way to avoid this datastep date1 and address the desired date formatting in the data null process instead?
You can avoid using data step at all if you want,
%let pmb=%sysfunc(INTNX(Month,&Rundate,-1,b),mmddyy10.);
%let pme=%sysfunc(INTNX(Month,&Rundate,-1,e),mmddyy10.);
Haikuo
Have you heard about date constants? They make date parameters so much easier to handle - they really are worth the effort of the learning.
They allow your code to look much more readable with proper dates rather than a number of days since 1960. Not just more readable but also much better for checking.
They work like:
WHERE dateVariable < "22dec2013"d
So it is really helpful that %SYSFUNC() can so easily provide the formatted dates like
%LET end_lastM = %SYSFUNC( INTNX( month, "&sysdate9"d, -1, E ), date9 ) ;
%LET beg_lastM = %SYSFUNC( INTNX( month, "&end_lastM"d, 0, B ), date9 ) ;
which might be used like
where tran_date between "&beg_lastM"d and "&end_lastM"
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.