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!!

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
  • 4 replies
  • 1008 views
  • 9 likes
  • 4 in conversation