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"

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
  • 2 replies
  • 1733 views
  • 0 likes
  • 3 in conversation