BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

 

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;

 

Output:

03APR17:01:04:3401APR17:00:00:0030APR17:23:59:59

Or for the current datetime:

 

data _null_;
    dt = datetime();
    fd = intnx('dtmonth', dt, 0, 'B');
    ld  = intnx('dtmonth', dt, 0, 'E');
    put dt datetime. fd datetime. ld datetime.;
run;

See also: INTNX and INTCK Function Examples.

View solution in original post

8 REPLIES 8
collinelliot
Barite | Level 11

 

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;

 

Output:

03APR17:01:04:3401APR17:00:00:0030APR17:23:59:59

Or for the current datetime:

 

data _null_;
    dt = datetime();
    fd = intnx('dtmonth', dt, 0, 'B');
    ld  = intnx('dtmonth', dt, 0, 'E');
    put dt datetime. fd datetime. ld datetime.;
run;

See also: INTNX and INTCK Function Examples.

JHE
Obsidian | Level 7 JHE
Obsidian | Level 7
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;
collinelliot
Barite | Level 11

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

 

datetime() will give you the current datetime value.

Reeza
Super User

@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. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

Thank you, let me try this way .

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 27634 views
  • 2 likes
  • 5 in conversation