BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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?

2 REPLIES 2
Haikuo
Onyx | Level 15

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

Peter_C
Rhodochrosite | Level 12

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"

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2336 views
  • 0 likes
  • 3 in conversation