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

Hello,

I'm looking to create prev month beg and end month datetime as macro variable in the below format using today's date.  Could someone please help me?

%Let PBOM_Dte = 2012-08-01 00:00:00;

%Let PEOM_Dte = 2012-08-31 23.59:59;

Thanks in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

proc format;

picture fmt

other='%Y-%0m-%0d %0H:%0M:%0S'(datatype=datetime);

run;

%let PBOM_Dte = %sysfunc(intnx(dtmonth,%sysfunc(datetime()),-1,b),fmt21. );

%put &PBOM_Dte ;

View solution in original post

4 REPLIES 4
Linlin
Lapis Lazuli | Level 10

data _null_; 

       call symputx('pbom_dte',catx(' ',put(intnx('month',today(),-1,'b'),yymmdd10.),'00:00:00'));

       call symputx('peom_dte',catx(' ',put(intnx('month',today(),-1,'e'),yymmdd10.),'23:59:59')); 

run;  

%put &pbom_dte;

%put &peom_dte;

/* log file */

65   %put &pbom_dte;

2012-08-01 00:00:00

66   %put &peom_dte;

2012-08-31 23:59:59

Ksharp
Super User

proc format;

picture fmt

other='%Y-%0m-%0d %0H:%0M:%0S'(datatype=datetime);

run;

%let PBOM_Dte = %sysfunc(intnx(dtmonth,%sysfunc(datetime()),-1,b),fmt21. );

%put &PBOM_Dte ;

shivas
Pyrite | Level 9

Hi Vicky,

Try this..some thing similar to Linlins code...

data _null_;

call symputx('pbom_dte',put(dhms(intnx('month',today(),-1,'b'),00,00,00),nldatm.));

call symputx('peom_dte',put(dhms(intnx('month',today(),-1,'e'),23,59,59),nldatm.));

run;

%put &pbom_dte;

%put &peom_dte;

Thanks,

Shiva

vicky07
Quartz | Level 8

All the three answers worked. Thanks to Ksharp,Shiva & Linlin!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1540 views
  • 9 likes
  • 4 in conversation