DATA Step, Macro, Functions and more

how to get first day and last day of month : 1APR2017 00:00:00 AND 30APR2017 23:59:59

Reply
Frequent Contributor
Frequent Contributor
Posts: 98

how to get first day and last day of month : 1APR2017 00:00:00 AND 30APR2017 23:59:59

 
Super User
Posts: 5,424

Re: how to get first day and last day of month : 1APR2017 00:00:00 AND 30APR2017 23:59:59

Intnx
Data never sleeps
Frequent Contributor
Frequent Contributor
Posts: 98

get first day and last day of month FORMAT AS: 1APR2017 00:00:00 AND 30APR2017 23:59:59

 
PROC Star
Posts: 307

Re: get first day and last day of month FORMAT AS: 1APR2017 00:00:00 AND 30APR2017 23:59:59

 

Get it from what? From a datetime value, you could use the intnx function.


data _null_;
    dt = '03APR2017:01:04:34'dt;
    fd = intnx('dtmonth', dt, 0, 'B');
    ld  = intnx('dtmonth', dt, 0, 'E');
    put dt datetime. fd datetime. ld datetime.;
run;
Frequent Contributor
Frequent Contributor
Posts: 98

Re: get first day and last day of month FORMAT AS: 1APR2017 00:00:00 AND 30APR2017 23:59:59

Posted in reply to collinelliot
If dt=today(), this would not working , dt would be dynamic variable .

data _null_;
dt = '03APR2017:01:04:34'dt;
fd = intnx('dtmonth', dt, 0, 'B');
ld = intnx('dtmonth', dt, 0, 'E');
put dt datetime. fd datetime. ld datetime.;
run;
PROC Star
Posts: 307

Re: get first day and last day of month FORMAT AS: 1APR2017 00:00:00 AND 30APR2017 23:59:59

Today() gives you a date, so you'd need to change the "dtmonth" to month.

 

datetime() will give you the current datetime value.

Super User
Posts: 19,771

Re: get first day and last day of month FORMAT AS: 1APR2017 00:00:00 AND 30APR2017 23:59:59


JHE wrote:
If dt=today(), this would not working , dt would be dynamic variable .

data _null_;
dt = '03APR2017:01:04:34'dt;
fd = intnx('dtmonth', dt, 0, 'B');
ld = intnx('dtmonth', dt, 0, 'E');
put dt datetime. fd datetime. ld datetime.;
run;

In the future please make something like this your first post, not just a subject line with no content. When you post only a vague subject  it's a processing of first trying to figure out your question before it can be answered, essentially playing 20 questions, which can be very annoying. 

Super User
Super User
Posts: 7,942

Re: how to get first day and last day of month : 1APR2017 00:00:00 AND 30APR2017 23:59:59

Maybe elaborate on your questions, post example test data in the form of a datastep, with what the output should look like.  I am guessing:

data want;
  start="01APR2017:00:00:00"dt;
  end=input(cats(put(intnx('month',datepart(start),'e'),date9.),":23:59:59"),datetime.);
  format start end datetime.;
run;

However with nothing to work with and no information...

Frequent Contributor
Frequent Contributor
Posts: 98

Re: how to get first day and last day of month : 1APR2017 00:00:00 AND 30APR2017 23:59:59

Thank you, let me try this way .

Ask a Question
Discussion stats
  • 8 replies
  • 1207 views
  • 0 likes
  • 5 in conversation