DATA Step, Macro, Functions and more

SAS datetime

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

SAS datetime

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!


Accepted Solutions
Solution
‎09-10-2012 11:20 PM
Super User
Posts: 10,044

Re: SAS datetime

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


All Replies
Super Contributor
Posts: 1,636

Re: SAS datetime

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

Solution
‎09-10-2012 11:20 PM
Super User
Posts: 10,044

Re: SAS datetime

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 ;

Super Contributor
Posts: 349

Re: SAS datetime

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

Contributor
Posts: 71

Re: SAS datetime

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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