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

Good day,

 

I am trying to extract just the day and Month dd-mmm from a datetime field.

The data is being pulled via Proc SQL; as the data resides on the SQL server.

e.DateOfBirth  give .17MAR1957:00:00:00.000  --> need --> 17-Mar

Its formatting in SQL is  datetime (length 8 )

 

Will appreciate any assistance.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
LeonidBatkhan
Lapis Lazuli | Level 10

Hi ColleenCB,

Here is how you can get various flavors of day&month:

 

data _null_;
   length y $6;
   x = '17MAR1957:00:00:00.000'dt;
   y = put(datepart(x),date5.); /* 17MAR */
   put y=;
   y = catx('-',substr(y,1,2),substr(y,3)); /* 17-MAR */
   put y=;
   y = propcase(y); /* 17-Mar */
   put y=;
run;

Hope this helps.

 

View solution in original post

6 REPLIES 6
ballardw
Super User

Please tell us how you intend to use the value like 17-Mar?

Typically I would use the DATEPART function to create a date value from the datetime and assign an appropriate format. But someone ignoring year may have other thoughts in mind.

You might also need to show how you expect single digit days of the month to appear.

 

proc format;
picture ddmon 
low-high = '%0d-%3b'   (datatype=date)
;
run;

data example;
   x="17MAR1957:00:00:00.000"dt;
   y=datepart(x);
   format  y ddmon.;
run;
   

By creating a date value, as in Y, you preserve the option of changing the display appearance by changing the display format as needed.

ColleenCB
Fluorite | Level 6

I like the formatting & it also works for my problem.

But not required in this exercise.

 

Thank you so much for answering me.

LeonidBatkhan
Lapis Lazuli | Level 10

Hi ColleenCB,

Here is how you can get various flavors of day&month:

 

data _null_;
   length y $6;
   x = '17MAR1957:00:00:00.000'dt;
   y = put(datepart(x),date5.); /* 17MAR */
   put y=;
   y = catx('-',substr(y,1,2),substr(y,3)); /* 17-MAR */
   put y=;
   y = propcase(y); /* 17-Mar */
   put y=;
run;

Hope this helps.

 

ColleenCB
Fluorite | Level 6
Thank you so much!
This worked perfectly.

Have a wonderful day
Kind Regards
Colleen Bronkhorst
Business Intelligence Analyst
FNB HR Employee Intelligence
1 First Place
BankCity
Tel: 0875 77 77 11

Rate my service:
Click on the link: Thank you for your rating
Select Nominate and enter my F-number 3340945
Select 1 or more Categories you wish to rate my service in
[cid:image001.jpg@01D6F7BE.38024C90]
Click on Nominate
dm



This email is subject to a disclaimer.

Visit the FNB website and view the email disclaimer and privacy notice / policy by clicking the "About FNB + Legal" and "Legal Matters" links.
If you are unable to access our website, please contact us to send you a copy of the email disclaimer or privacy notice / policy .
ColleenCB
Fluorite | Level 6

Thank you so much for this post.

I will need to keep it save and use it more often - practice makes perfect.

This works perfectly for my requirement.

 

Have a wonderful day

Tom
Super User Tom
Super User

Do you really need the hyphen?  If not just use DTDATE5. format.

426  data test;
427    dob = '17MAR1957:00:00:00.000'dt ;
428    put dob dtdate5. ;
429  run;

17MAR

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
  • 6 replies
  • 695 views
  • 7 likes
  • 4 in conversation